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