diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-04-22 22:07:54 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-04-22 22:18:07 +0200 |
commit | c96993d22c7b1a41b4c0152985e8193496cdaaae (patch) | |
tree | 43a995216518361b8795b2fe8db358753dfd966c /sonar-plugin-api/src/test/java/org/sonar | |
parent | c8d6f37f0f6ff1bc7c6107350e4954bda086a14d (diff) | |
download | sonarqube-c96993d22c7b1a41b4c0152985e8193496cdaaae.tar.gz sonarqube-c96993d22c7b1a41b4c0152985e8193496cdaaae.zip |
SONAR-6200 New Sensor API to report UT/IT/Overall coverage
Diffstat (limited to 'sonar-plugin-api/src/test/java/org/sonar')
2 files changed, 38 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java index 6b8b6af9fea..3e3339bf63d 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java @@ -166,6 +166,12 @@ public class DefaultInputFileTest { } catch (Exception e) { assertThat(e).hasMessage("Start pointer [line=1, lineOffset=0] should be before end pointer [line=1, lineOffset=0]"); } + try { + file.newRange(file.newPointer(1, 0), file.newPointer(1, 10)); + fail(); + } catch (Exception e) { + assertThat(e).hasMessage("10 is not a valid line offset for pointer. File [moduleKey=ABCDE, relative=src/Foo.php, basedir=null] has 9 character(s) at line 1"); + } } @Test diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java index c1784a24dfc..8fcc6f3a6ce 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java @@ -29,6 +29,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.FileMetadata; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; +import org.sonar.api.batch.sensor.coverage.CoverageType; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.config.Settings; import org.sonar.api.measures.CoreMetrics; @@ -176,4 +177,35 @@ public class SensorContextTesterTest { .save(); assertThat(tester.dependencies()).hasSize(1); } + + @Test + public void testLineHits() { + assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 1)).isNull(); + assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 4)).isNull(); + tester.newCoverage() + .onFile(new DefaultInputFile("foo", "src/Foo.java").initMetadata(new FileMetadata().readMetadata(new StringReader("annot dsf fds foo bar")))) + .ofType(CoverageType.UNIT) + .lineHits(1, 2) + .lineHits(4, 3) + .save(); + assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 1)).isEqualTo(2); + assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.IT, 1)).isNull(); + assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 4)).isEqualTo(3); + } + + @Test + public void testConditions() { + assertThat(tester.conditions("foo:src/Foo.java", CoverageType.UNIT, 1)).isNull(); + assertThat(tester.coveredConditions("foo:src/Foo.java", CoverageType.UNIT, 1)).isNull(); + tester.newCoverage() + .onFile(new DefaultInputFile("foo", "src/Foo.java").initMetadata(new FileMetadata().readMetadata(new StringReader("annot dsf fds foo bar")))) + .ofType(CoverageType.UNIT) + .conditions(1, 4, 2) + .save(); + assertThat(tester.conditions("foo:src/Foo.java", CoverageType.UNIT, 1)).isEqualTo(4); + assertThat(tester.coveredConditions("foo:src/Foo.java", CoverageType.UNIT, 1)).isEqualTo(2); + + assertThat(tester.conditions("foo:src/Foo.java", CoverageType.IT, 1)).isNull(); + assertThat(tester.coveredConditions("foo:src/Foo.java", CoverageType.IT, 1)).isNull(); + } } |