}
+ @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());
}
--- /dev/null
+<?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>