aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-02-28 18:33:17 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-02-28 18:33:17 +0100
commitf024f9b98e38f84729d2a82affdffbd4c98bd68b (patch)
tree6e0741e5705fac32b699a9bdcbaa7bf4d8be878b /plugins
parent1ec6704480f79ab80b0c43c2a663d810df93f1b7 (diff)
downloadsonarqube-f024f9b98e38f84729d2a82affdffbd4c98bd68b.tar.gz
sonarqube-f024f9b98e38f84729d2a82affdffbd4c98bd68b.zip
SONAR-2246 Cobertura: wrong uncovered lines and uncovered conditions on anonymous classes
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java12
-rw-r--r--plugins/sonar-cobertura-plugin/src/test/resources/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml40
2 files changed, 52 insertions, 0 deletions
diff --git a/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java b/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
index c14f11e160a..682f4e682af 100644
--- a/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
+++ b/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
@@ -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
index 00000000000..55fa2986d6a
--- /dev/null
+++ b/plugins/sonar-cobertura-plugin/src/test/resources/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml
@@ -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>