use of org.sonar.scanner.protocol.output.ScannerReport.LineCoverage in project sonarqube by SonarSource.
the class CoveragePublisherTest method publishCoverage.
@Test
public void publishCoverage() throws Exception {
DefaultMeasure<String> utLineHits = new DefaultMeasure<String>().forMetric(CoreMetrics.COVERAGE_LINE_HITS_DATA).withValue("2=1;3=1;5=0;6=3");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY)).thenReturn((DefaultMeasure) utLineHits);
DefaultMeasure<String> conditionsByLine = new DefaultMeasure<String>().forMetric(CoreMetrics.CONDITIONS_BY_LINE).withValue("3=4");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.CONDITIONS_BY_LINE_KEY)).thenReturn((DefaultMeasure) conditionsByLine);
DefaultMeasure<String> coveredConditionsByUts = new DefaultMeasure<String>().forMetric(CoreMetrics.COVERED_CONDITIONS_BY_LINE).withValue("3=2");
when(measureCache.byMetric("foo:src/Foo.php", CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY)).thenReturn((DefaultMeasure) coveredConditionsByUts);
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
publisher.publish(writer);
try (CloseableIterator<LineCoverage> it = new ScannerReportReader(outputDir).readComponentCoverage(inputFile.batchId())) {
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(2).setHits(true).build());
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(3).setHits(true).setConditions(4).setCoveredConditions(2).build());
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder().setLine(5).setHits(false).build());
}
}
Aggregations