From f024f9b98e38f84729d2a82affdffbd4c98bd68b Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 28 Feb 2011 18:33:17 +0100 Subject: [PATCH] SONAR-2246 Cobertura: wrong uncovered lines and uncovered conditions on anonymous classes --- .../cobertura/CoberturaSensorTest.java | 12 ++++++ .../shouldNotCountTwiceAnonymousClasses.xml | 40 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 plugins/sonar-cobertura-plugin/src/test/resources/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldNotCountTwiceAnonymousClasses.xml 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 @@ + + + + + + + + + + + + /Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java + --source + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5