]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2246 Cobertura: wrong uncovered lines and uncovered conditions on anonymous...
authorsimonbrandhof <simon.brandhof@gmail.com>
Mon, 28 Feb 2011 17:33:17 +0000 (18:33 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Mon, 28 Feb 2011 17:33:17 +0000 (18:33 +0100)
plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
plugins/sonar-cobertura-plugin/src/test/resources/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml [new file with mode: 0644]

index c14f11e160a1a6b3d2ab161fb2d8e8051f3f667b..682f4e682af0ade34d9ca399b8e0f9255e6853bd 100644 (file)
@@ -201,6 +201,18 @@ public class CoberturaSensorTest {
   }
 
 
+  @Test
+  public void shouldNotCountTwiceAnonymousClasses() throws URISyntaxException {
+    File coverage = new File(getClass().getResource("/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml").toURI());
+    SensorContext context = mock(SensorContext.class);
+    when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.samples.MyClass"));
+    new CoberturaSensor().parseReport(coverage, context);
+
+    verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.MyFile")),
+        argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 5.0))); // do not count line 26 twice
+  }
+
+
   private File getCoverageReport() throws URISyntaxException {
     return new File(getClass().getResource("/org/sonar/plugins/cobertura/CoberturaSensorTest/commons-chain-coverage.xml").toURI());
   }
diff --git a/plugins/sonar-cobertura-plugin/src/test/resources/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml b/plugins/sonar-cobertura-plugin/src/test/resources/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml
new file mode 100644 (file)
index 0000000..55fa298
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
+
+
+
+<!-- line 26 is defined in two nodes -->    
+
+
+
+<coverage line-rate="0.37142857142857144" branch-rate="0.25" lines-covered="13" lines-valid="35" branches-covered="1"
+          branches-valid="4" complexity="1.3076923076923077" version="1.9.2" timestamp="1253274062754">
+  <sources>
+    <source>/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java</source>
+    <source>--source</source>
+  </sources>
+  <packages>
+    <package name="org.sonar.samples" line-rate="0.37142857142857144" branch-rate="0.25"
+             complexity="1.3076923076923077">
+      <classes>
+        <class name="MyClass" filename="org/sonar/samples/MyFile.java"
+               line-rate="0.5384615384615384" branch-rate="0.5" complexity="1.3076923076923077">
+          <lines>
+            <line number="22" hits="2" branch="false"/>
+            <line number="25" hits="0" branch="false"/>
+            <line number="26" hits="0" branch="false"/>
+          </lines>
+        </class>
+        <class name="MyClass$1" filename="org/sonar/samples/MyFile.java"
+               line-rate="0.5384615384615384" branch-rate="0.5" complexity="1.3076923076923077">
+          <lines>
+
+            <line number="26" hits="0" branch="false"/>
+            <line number="27" hits="0" branch="false"/>
+            <line number="28" hits="0" branch="false"/>
+          </lines>
+        </class>
+      </classes>
+    </package>
+  </packages>
+</coverage>