diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-29 18:13:12 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-30 11:32:39 +0200 |
commit | 946a448c08ccc10ad1c0af778ae5d9f179655ef8 (patch) | |
tree | 14acab59210015b9a2e3aeba04a7b54bcfa5fc19 /server | |
parent | 2cf5d0f82c96846af16007233b674e0e5c638eea (diff) | |
download | sonarqube-946a448c08ccc10ad1c0af778ae5d9f179655ef8.tar.gz sonarqube-946a448c08ccc10ad1c0af778ae5d9f179655ef8.zip |
SONAR-7497 Restore behavior for line coverage after move to proto3
Diffstat (limited to 'server')
2 files changed, 81 insertions, 8 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/source/CoverageLineReader.java b/server/sonar-server/src/main/java/org/sonar/server/computation/source/CoverageLineReader.java index 19f8a80d611..9f30c7adfbe 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/source/CoverageLineReader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/source/CoverageLineReader.java @@ -23,6 +23,11 @@ import java.util.Iterator; import javax.annotation.CheckForNull; import org.sonar.db.protobuf.DbFileSources; import org.sonar.scanner.protocol.output.ScannerReport; +import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasItCoveredConditionsCase; +import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasItHitsCase; +import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasOverallCoveredConditionsCase; +import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasUtCoveredConditionsCase; +import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasUtHitsCase; public class CoverageLineReader implements LineReader { @@ -45,24 +50,30 @@ public class CoverageLineReader implements LineReader { } private static void processUnitTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) { - lineBuilder.setUtLineHits(reportCoverage.getUtHits() ? 1 : 0); - if (reportCoverage.getConditions() > 0) { + if (reportCoverage.getHasUtHitsCase() == HasUtHitsCase.UT_HITS) { + lineBuilder.setUtLineHits(reportCoverage.getUtHits() ? 1 : 0); + } + if (reportCoverage.getHasUtCoveredConditionsCase() == HasUtCoveredConditionsCase.UT_COVERED_CONDITIONS) { lineBuilder.setUtConditions(reportCoverage.getConditions()); lineBuilder.setUtCoveredConditions(reportCoverage.getUtCoveredConditions()); } } private static void processIntegrationTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) { - lineBuilder.setItLineHits(reportCoverage.getItHits() ? 1 : 0); - if (reportCoverage.getConditions() > 0) { + if (reportCoverage.getHasItHitsCase() == HasItHitsCase.IT_HITS) { + lineBuilder.setItLineHits(reportCoverage.getItHits() ? 1 : 0); + } + if (reportCoverage.getHasItCoveredConditionsCase() == HasItCoveredConditionsCase.IT_COVERED_CONDITIONS) { lineBuilder.setItConditions(reportCoverage.getConditions()); lineBuilder.setItCoveredConditions(reportCoverage.getItCoveredConditions()); } } private static void processOverallTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) { - lineBuilder.setOverallLineHits((reportCoverage.getUtHits() || reportCoverage.getItHits()) ? 1 : 0); - if (reportCoverage.getConditions() > 0) { + if (reportCoverage.getHasUtHitsCase() == HasUtHitsCase.UT_HITS || reportCoverage.getHasItHitsCase() == HasItHitsCase.IT_HITS) { + lineBuilder.setOverallLineHits((reportCoverage.getUtHits() || reportCoverage.getItHits()) ? 1 : 0); + } + if (reportCoverage.getHasOverallCoveredConditionsCase() == HasOverallCoveredConditionsCase.OVERALL_COVERED_CONDITIONS) { lineBuilder.setOverallConditions(reportCoverage.getConditions()); lineBuilder.setOverallCoveredConditions(reportCoverage.getOverallCoveredConditions()); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/source/CoverageLineReaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/source/CoverageLineReaderTest.java index 1f211b59363..881e9a4bed7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/source/CoverageLineReaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/source/CoverageLineReaderTest.java @@ -53,6 +53,70 @@ public class CoverageLineReaderTest { assertThat(lineBuilder.getOverallConditions()).isEqualTo(10); } + // Some tools are only able to report condition coverage + @Test + public void set_coverage_only_conditions() { + CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() + .setLine(1) + .setConditions(10) + .setUtCoveredConditions(2) + .setItCoveredConditions(3) + .build()).iterator()); + + DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); + computeCoverageLine.read(lineBuilder); + + assertThat(lineBuilder.hasUtLineHits()).isFalse(); + assertThat(lineBuilder.getUtConditions()).isEqualTo(10); + assertThat(lineBuilder.hasItLineHits()).isFalse(); + assertThat(lineBuilder.getItConditions()).isEqualTo(10); + assertThat(lineBuilder.getItCoveredConditions()).isEqualTo(3); + assertThat(lineBuilder.hasOverallLineHits()).isFalse(); + assertThat(lineBuilder.hasOverallConditions()).isFalse(); + } + + @Test + public void set_coverage_only_ut() { + CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() + .setLine(1) + .setConditions(10) + .setUtHits(true) + .setUtCoveredConditions(2) + .build()).iterator()); + + DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); + computeCoverageLine.read(lineBuilder); + + assertThat(lineBuilder.getUtLineHits()).isEqualTo(1); + assertThat(lineBuilder.getUtConditions()).isEqualTo(10); + assertThat(lineBuilder.hasItLineHits()).isFalse(); + assertThat(lineBuilder.hasItConditions()).isFalse(); + assertThat(lineBuilder.hasItCoveredConditions()).isFalse(); + assertThat(lineBuilder.getOverallLineHits()).isEqualTo(1); + assertThat(lineBuilder.hasOverallCoveredConditions()).isFalse(); + } + + @Test + public void set_coverage_only_it() { + CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() + .setLine(1) + .setConditions(10) + .setItHits(true) + .setItCoveredConditions(3) + .build()).iterator()); + + DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); + computeCoverageLine.read(lineBuilder); + + assertThat(lineBuilder.hasUtLineHits()).isFalse(); + assertThat(lineBuilder.hasUtConditions()).isFalse(); + assertThat(lineBuilder.getItLineHits()).isEqualTo(1); + assertThat(lineBuilder.getItConditions()).isEqualTo(10); + assertThat(lineBuilder.getItCoveredConditions()).isEqualTo(3); + assertThat(lineBuilder.getOverallLineHits()).isEqualTo(1); + assertThat(lineBuilder.hasOverallConditions()).isFalse(); + } + @Test public void set_coverage_on_uncovered_lines() { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() @@ -77,7 +141,6 @@ public class CoverageLineReaderTest { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) .setUtHits(true) - .setItHits(false) .build()).iterator()); DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); @@ -90,7 +153,6 @@ public class CoverageLineReaderTest { public void set_overall_line_hits_with_only_it() { CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder() .setLine(1) - .setUtHits(false) .setItHits(true) .build()).iterator()); |