From eb70a3ce1544f7e685cc96bd55af6f273ff76181 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Wed, 14 Jan 2015 17:12:51 +0100 Subject: [PATCH] Add and adapt cobertura unit tests --- .../scala/cobertura/CoberturaSensorTest.java | 30 ++--- .../commons-chain-coverage.xml | 122 +++++++++--------- .../shouldNotCountTwiceAnonymousClasses.xml | 38 ------ 3 files changed, 74 insertions(+), 116 deletions(-) delete mode 100644 src/test/resources/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml diff --git a/src/test/java/org/sonar/plugins/scala/cobertura/CoberturaSensorTest.java b/src/test/java/org/sonar/plugins/scala/cobertura/CoberturaSensorTest.java index 80b5337..7fd1301 100644 --- a/src/test/java/org/sonar/plugins/scala/cobertura/CoberturaSensorTest.java +++ b/src/test/java/org/sonar/plugins/scala/cobertura/CoberturaSensorTest.java @@ -17,6 +17,9 @@ * License along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ +/* + * SonarQube Cobertura Plugin + */ package org.sonar.plugins.scala.cobertura; import static org.mockito.Matchers.any; @@ -157,27 +160,20 @@ public void testDoNotSaveMeasureOnResourceWhichDoesntExistInTheContext() throws } @Test - public void javaInterfaceHasNoCoverage() throws URISyntaxException { + public void collectFileLineHitsData() throws URISyntaxException { + DefaultInputFile file = new DefaultInputFile("org/apache/commons/chain/impl/CatalogBase.scala"); + fs.add(file); + sensor = new CoberturaSensor(fs, pathResolver, settings); sensor.parseReport(getCoverageReport(), context); - - final Resource interfaze = new org.sonar.api.resources.File("org/apache/commons/chain/Chain"); - - - verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.COVERAGE))); - - verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.LINE_COVERAGE))); - verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER))); - verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES))); - - verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.BRANCH_COVERAGE))); - verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER))); - verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS))); + verify(context).saveMeasure( + eq(file), + argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA, + "48=117;56=234;66=0;67=0;68=0;84=999;86=999;98=318;111=18;121=0;122=0;125=0;126=0;127=0;128=0;131=0;133=0"))); } private File getCoverageReport() throws URISyntaxException { - return new File(getClass().getResource("/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/commons-chain-coverage.xml").toURI()); - } - + return new File(getClass().getResource("/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/commons-chain-coverage.xml").toURI()); + } @Test public void should_execute_if_filesystem_contains_scala_files() { diff --git a/src/test/resources/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/commons-chain-coverage.xml b/src/test/resources/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/commons-chain-coverage.xml index adb4f7b..e4656d2 100644 --- a/src/test/resources/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/commons-chain-coverage.xml +++ b/src/test/resources/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/commons-chain-coverage.xml @@ -12,14 +12,14 @@ - - @@ -226,28 +226,28 @@ - - - - @@ -260,7 +260,7 @@ complexity="1.4333333333333333"> @@ -512,7 +512,7 @@ @@ -607,7 +607,7 @@ @@ -779,7 +779,7 @@ complexity="1.98"> @@ -875,7 +875,7 @@ @@ -1062,7 +1062,7 @@ @@ -1253,7 +1253,7 @@ @@ -1611,7 +1611,7 @@ @@ -1654,7 +1654,7 @@ complexity="2.59375"> @@ -1738,7 +1738,7 @@ @@ -1805,7 +1805,7 @@ - @@ -2079,7 +2079,7 @@ @@ -2674,7 +2674,7 @@ @@ -2694,7 +2694,7 @@ @@ -3168,7 +3168,7 @@ @@ -3206,7 +3206,7 @@ @@ -3657,7 +3657,7 @@ @@ -4098,7 +4098,7 @@ @@ -4281,7 +4281,7 @@ - - @@ -4414,7 +4414,7 @@ @@ -4437,7 +4437,7 @@ @@ -4462,7 +4462,7 @@ @@ -4574,7 +4574,7 @@ complexity="2.1826086956521737"> @@ -4889,7 +4889,7 @@ @@ -4912,7 +4912,7 @@ @@ -5155,7 +5155,7 @@ @@ -5398,7 +5398,7 @@ @@ -5641,7 +5641,7 @@ @@ -5956,7 +5956,7 @@ @@ -6451,7 +6451,7 @@ @@ -6472,7 +6472,7 @@ @@ -6753,7 +6753,7 @@ complexity="2.161111111111111"> @@ -6873,7 +6873,7 @@ @@ -6949,7 +6949,7 @@ @@ -7029,7 +7029,7 @@ @@ -7344,7 +7344,7 @@ @@ -7677,7 +7677,7 @@ @@ -8499,7 +8499,7 @@ @@ -9063,7 +9063,7 @@ @@ -9900,7 +9900,7 @@ diff --git a/src/test/resources/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml b/src/test/resources/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml deleted file mode 100644 index 2ff6a2c..0000000 --- a/src/test/resources/org/sonar/plugins/scala/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - /Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java - --source - - - - - - - - - - - - - - - - - - - - - - -