Search in sources :

Example 1 with LineCoverage

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());
    }
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultMeasure(org.sonar.api.batch.sensor.measure.internal.DefaultMeasure) LineCoverage(org.sonar.scanner.protocol.output.ScannerReport.LineCoverage) Matchers.anyString(org.mockito.Matchers.anyString) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)1 LineCoverage (org.sonar.scanner.protocol.output.ScannerReport.LineCoverage)1 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)1 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)1