diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-08-16 22:41:04 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-08-16 22:43:40 +0200 |
commit | b9395c6abef43d82f2936a17af85ce02cbebb834 (patch) | |
tree | dcf4485a1d04f91899e6934233e07d9631371c72 /plugins/sonar-surefire-plugin | |
parent | 8aec473335220716f4d4c68f8075a8248597e363 (diff) | |
download | sonarqube-b9395c6abef43d82f2936a17af85ce02cbebb834.tar.gz sonarqube-b9395c6abef43d82f2936a17af85ce02cbebb834.zip |
SONAR-2677 JUnit tests containing several level of nested inner classes can't be analysed by Sonar
Diffstat (limited to 'plugins/sonar-surefire-plugin')
6 files changed, 197 insertions, 2 deletions
diff --git a/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java b/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java index 85e7a2682f8..f2c22cb15b9 100644 --- a/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java +++ b/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java @@ -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); } } diff --git a/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/data/SurefireStaxHandler.java b/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/data/SurefireStaxHandler.java index b9a0b3b9e41..38ebc7b3571 100644 --- a/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/data/SurefireStaxHandler.java +++ b/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/data/SurefireStaxHandler.java @@ -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 index 00000000000..aae1f119a48 --- /dev/null +++ b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/FooTest.java @@ -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 diff --git a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java index e4d195ebe42..51c666a6843 100644 --- a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java +++ b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java @@ -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 index 00000000000..b3357bd1f87 --- /dev/null +++ b/plugins/sonar-surefire-plugin/src/test/resources/org/sonar/plugins/surefire/api/AbstractSurefireParserTest/nestedInnerClasses/TEST-org.sonar.plugins.surefire.NestedTest$Inner1$Run.xml @@ -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 "clean" "install""/> + <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 index 00000000000..677686a7aa3 --- /dev/null +++ b/plugins/sonar-surefire-plugin/src/test/resources/org/sonar/plugins/surefire/api/AbstractSurefireParserTest/nestedInnerClasses/TEST-org.sonar.plugins.surefire.NestedTest$Inner2$Run.xml @@ -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 "clean" "install""/> + <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 |