]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2677 JUnit tests containing several level of nested inner classes can't be...
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 16 Aug 2011 20:41:04 +0000 (22:41 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 16 Aug 2011 20:43:40 +0000 (22:43 +0200)
plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java
plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/data/SurefireStaxHandler.java
plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/FooTest.java [new file with mode: 0644]
plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java
plugins/sonar-surefire-plugin/src/test/resources/org/sonar/plugins/surefire/api/AbstractSurefireParserTest/nestedInnerClasses/TEST-org.sonar.plugins.surefire.NestedTest$Inner1$Run.xml [new file with mode: 0644]
plugins/sonar-surefire-plugin/src/test/resources/org/sonar/plugins/surefire/api/AbstractSurefireParserTest/nestedInnerClasses/TEST-org.sonar.plugins.surefire.NestedTest$Inner2$Run.xml [new file with mode: 0644]

index 85e7a2682f841fbbd35cb1d304737dcb8bef48e9..f2c22cb15b99682127ea340142ee42bbe6e7b17e 100644 (file)
@@ -91,7 +91,7 @@ public abstract class AbstractSurefireParser {
     for (String classname : index.getClassnames()) {
       if (StringUtils.contains(classname, "$")) {
         // Surefire reports classes whereas sonar supports files
-        String parentClassName = StringUtils.substringBeforeLast(classname, "$");
+        String parentClassName = StringUtils.substringBefore(classname, "$");
         index.merge(classname, parentClassName);
       }
     }
index b9a0b3b9e41fd9424eaaf8e8501e349dea4a72a2..38ebc7b35710c87a816d935839e93c856b1a7f52 100644 (file)
@@ -125,7 +125,7 @@ public class SurefireStaxHandler implements XmlStreamHandler {
     String classname = testCaseCursor.getAttrValue("classname");
     String name = testCaseCursor.getAttrValue("name");
     if (StringUtils.contains(classname, "$")) {
-      return StringUtils.substringAfterLast(classname, "$") + "/" + name;
+      return StringUtils.substringAfter(classname, "$") + "/" + name;
     }
     return name;
   }
diff --git a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/FooTest.java b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/FooTest.java
new file mode 100644 (file)
index 0000000..aae1f11
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.surefire;
+
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+
+@RunWith(Enclosed.class)
+public class FooTest  {
+
+  @RunWith(Enclosed.class)
+  public static class Inner1 {
+
+    public static class Run {
+      @Test
+      public void test1() {}
+    }
+  }
+
+  @RunWith(Enclosed.class)
+  public static class Inner2 {
+
+    public static class Run {
+      @Test
+      public void test2() {}
+    }
+  }
+}
\ No newline at end of file
index e4d195ebe4243c6efc3a7d99134460fdc3ed9bbf..51c666a68437c42b61e4289d143b05663c620d77 100644 (file)
@@ -111,6 +111,19 @@ public class AbstractSurefireParserTest {
     verify(context, never()).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.apache.commons.collections.bidimap.AbstractTestBidiMap$TestBidiMapEntrySet")), any(Metric.class), anyDouble());
   }
 
+  @Test
+  public void shouldMergeNestedInnerClasses() throws URISyntaxException {
+    AbstractSurefireParser parser = newParser();
+
+    SensorContext context = mockContext();
+    parser.collect(new Project("foo"), context, getDir("nestedInnerClasses"));
+
+    verify(context).saveMeasure(
+        argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.plugins.surefire.NestedInnerTest")),
+        eq(CoreMetrics.TESTS),
+        eq(3.0));
+  }
+
 
   private AbstractSurefireParser newParser() {
     return new AbstractSurefireParser() {
diff --git a/plugins/sonar-surefire-plugin/src/test/resources/org/sonar/plugins/surefire/api/AbstractSurefireParserTest/nestedInnerClasses/TEST-org.sonar.plugins.surefire.NestedTest$Inner1$Run.xml b/plugins/sonar-surefire-plugin/src/test/resources/org/sonar/plugins/surefire/api/AbstractSurefireParserTest/nestedInnerClasses/TEST-org.sonar.plugins.surefire.NestedTest$Inner1$Run.xml
new file mode 100644 (file)
index 0000000..b3357bd
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<testsuite failures="0" time="0.001" errors="0" skipped="0" tests="1" name="org.sonar.plugins.surefire.NestedInnerTest">
+  <properties>
+    <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
+    <property name="sun.boot.library.path" value="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries"/>
+    <property name="java.vm.version" value="20.1-b02-384"/>
+    <property name="awt.nativeDoubleBuffering" value="true"/>
+    <property name="gopherProxySet" value="false"/>
+    <property name="mrj.build" value="10M3425"/>
+    <property name="java.vm.vendor" value="Apple Inc."/>
+    <property name="java.vendor.url" value="http://www.apple.com/"/>
+    <property name="path.separator" value=":"/>
+    <property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
+    <property name="file.encoding.pkg" value="sun.io"/>
+    <property name="user.country" value="US"/>
+    <property name="sun.java.launcher" value="SUN_STANDARD"/>
+    <property name="sun.os.patch.level" value="unknown"/>
+    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
+    <property name="user.dir" value="/Users/sbrandhof/projects/github/sonar/plugins/sonar-surefire-plugin"/>
+    <property name="java.runtime.version" value="1.6.0_26-b03-384-10M3425"/>
+    <property name="java.awt.graphicsenv" value="apple.awt.CGraphicsEnvironment"/>
+    <property name="java.endorsed.dirs" value="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/endorsed"/>
+    <property name="os.arch" value="x86_64"/>
+    <property name="java.io.tmpdir" value="/var/folders/H1/H1p3aGauF5myqknnfgovp++++TI/-Tmp-/"/>
+    <property name="line.separator" value="
+"/>
+    <property name="java.vm.specification.vendor" value="Sun Microsystems Inc."/>
+    <property name="os.name" value="Mac OS X"/>
+    <property name="classworlds.conf" value="/Users/sbrandhof/Dropbox/dev/softwares/apache-maven-2.2.1/bin/m2.conf"/>
+    <property name="sun.jnu.encoding" value="MacRoman"/>
+    <property name="java.library.path" value=".:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java"/>
+    <property name="java.specification.name" value="Java Platform API Specification"/>
+    <property name="java.class.version" value="50.0"/>
+    <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
+    <property name="os.version" value="10.6.8"/>
+    <property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="user.home" value="/Users/sbrandhof"/>
+    <property name="user.timezone" value="Europe/Paris"/>
+    <property name="java.awt.printerjob" value="apple.awt.CPrinterJob"/>
+    <property name="java.specification.version" value="1.6"/>
+    <property name="file.encoding" value="MacRoman"/>
+    <property name="user.name" value="sbrandhof"/>
+    <property name="java.class.path" value="/Users/sbrandhof/Dropbox/dev/softwares/apache-maven-2.2.1/boot/classworlds-1.1.jar"/>
+    <property name="java.vm.specification.version" value="1.0"/>
+    <property name="sun.arch.data.model" value="64"/>
+    <property name="java.home" value="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"/>
+    <property name="sun.java.command" value="org.codehaus.classworlds.Launcher &quot;clean&quot; &quot;install&quot;"/>
+    <property name="java.specification.vendor" value="Sun Microsystems Inc."/>
+    <property name="user.language" value="en"/>
+    <property name="awt.toolkit" value="apple.awt.CToolkit"/>
+    <property name="java.vm.info" value="mixed mode"/>
+    <property name="java.version" value="1.6.0_26"/>
+    <property name="java.ext.dirs" value="/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext"/>
+    <property name="sun.boot.class.path" value="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar"/>
+    <property name="java.vendor" value="Apple Inc."/>
+    <property name="maven.home" value="/Users/sbrandhof/Dropbox/dev/softwares/apache-maven-2.2.1"/>
+    <property name="file.separator" value="/"/>
+    <property name="java.vendor.url.bug" value="http://bugreport.apple.com/"/>
+    <property name="sun.cpu.endian" value="little"/>
+    <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
+    <property name="mrj.version" value="1060.1.6.0_26-384"/>
+    <property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="sun.cpu.isalist" value=""/>
+  </properties>
+  <testcase time="0" classname="org.sonar.plugins.surefire.NestedInnerTest$Inner1$Run" name="test1"/>
+  <testcase time="0" classname="org.sonar.plugins.surefire.NestedInnerTest$Inner2$Run" name="test2"/>
+  <testcase time="0" classname="org.sonar.plugins.surefire.NestedInnerTest$Inner3$Run" name="test3"/>
+</testsuite>
\ No newline at end of file
diff --git a/plugins/sonar-surefire-plugin/src/test/resources/org/sonar/plugins/surefire/api/AbstractSurefireParserTest/nestedInnerClasses/TEST-org.sonar.plugins.surefire.NestedTest$Inner2$Run.xml b/plugins/sonar-surefire-plugin/src/test/resources/org/sonar/plugins/surefire/api/AbstractSurefireParserTest/nestedInnerClasses/TEST-org.sonar.plugins.surefire.NestedTest$Inner2$Run.xml
new file mode 100644 (file)
index 0000000..677686a
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<testsuite failures="0" time="0.023" errors="0" skipped="0" tests="1" name="org.sonar.plugins.surefire.NestedInnerTest$Inner2$Run">
+  <properties>
+    <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
+    <property name="sun.boot.library.path" value="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries"/>
+    <property name="java.vm.version" value="20.1-b02-384"/>
+    <property name="awt.nativeDoubleBuffering" value="true"/>
+    <property name="gopherProxySet" value="false"/>
+    <property name="mrj.build" value="10M3425"/>
+    <property name="java.vm.vendor" value="Apple Inc."/>
+    <property name="java.vendor.url" value="http://www.apple.com/"/>
+    <property name="path.separator" value=":"/>
+    <property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
+    <property name="file.encoding.pkg" value="sun.io"/>
+    <property name="user.country" value="US"/>
+    <property name="sun.java.launcher" value="SUN_STANDARD"/>
+    <property name="sun.os.patch.level" value="unknown"/>
+    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
+    <property name="user.dir" value="/Users/sbrandhof/projects/github/sonar/plugins/sonar-surefire-plugin"/>
+    <property name="java.runtime.version" value="1.6.0_26-b03-384-10M3425"/>
+    <property name="java.awt.graphicsenv" value="apple.awt.CGraphicsEnvironment"/>
+    <property name="java.endorsed.dirs" value="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/endorsed"/>
+    <property name="os.arch" value="x86_64"/>
+    <property name="java.io.tmpdir" value="/var/folders/H1/H1p3aGauF5myqknnfgovp++++TI/-Tmp-/"/>
+    <property name="line.separator" value="
+"/>
+    <property name="java.vm.specification.vendor" value="Sun Microsystems Inc."/>
+    <property name="os.name" value="Mac OS X"/>
+    <property name="classworlds.conf" value="/Users/sbrandhof/Dropbox/dev/softwares/apache-maven-2.2.1/bin/m2.conf"/>
+    <property name="sun.jnu.encoding" value="MacRoman"/>
+    <property name="java.library.path" value=".:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java"/>
+    <property name="java.specification.name" value="Java Platform API Specification"/>
+    <property name="java.class.version" value="50.0"/>
+    <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
+    <property name="os.version" value="10.6.8"/>
+    <property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="user.home" value="/Users/sbrandhof"/>
+    <property name="user.timezone" value="Europe/Paris"/>
+    <property name="java.awt.printerjob" value="apple.awt.CPrinterJob"/>
+    <property name="java.specification.version" value="1.6"/>
+    <property name="file.encoding" value="MacRoman"/>
+    <property name="user.name" value="sbrandhof"/>
+    <property name="java.class.path" value="/Users/sbrandhof/Dropbox/dev/softwares/apache-maven-2.2.1/boot/classworlds-1.1.jar"/>
+    <property name="java.vm.specification.version" value="1.0"/>
+    <property name="sun.arch.data.model" value="64"/>
+    <property name="java.home" value="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"/>
+    <property name="sun.java.command" value="org.codehaus.classworlds.Launcher &quot;clean&quot; &quot;install&quot;"/>
+    <property name="java.specification.vendor" value="Sun Microsystems Inc."/>
+    <property name="user.language" value="en"/>
+    <property name="awt.toolkit" value="apple.awt.CToolkit"/>
+    <property name="java.vm.info" value="mixed mode"/>
+    <property name="java.version" value="1.6.0_26"/>
+    <property name="java.ext.dirs" value="/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext"/>
+    <property name="sun.boot.class.path" value="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar"/>
+    <property name="java.vendor" value="Apple Inc."/>
+    <property name="maven.home" value="/Users/sbrandhof/Dropbox/dev/softwares/apache-maven-2.2.1"/>
+    <property name="file.separator" value="/"/>
+    <property name="java.vendor.url.bug" value="http://bugreport.apple.com/"/>
+    <property name="sun.cpu.endian" value="little"/>
+    <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
+    <property name="mrj.version" value="1060.1.6.0_26-384"/>
+    <property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="sun.cpu.isalist" value=""/>
+  </properties>
+  <testcase time="0" classname="org.sonar.plugins.surefire.NestedInnerTest$Inner2$Run" name="test2"/>
+</testsuite>
\ No newline at end of file