Repository: maven-surefire Updated Branches: refs/heads/master 33105af2e -> 378097657
[SUREFIRE] refactoring after Sonar report Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/37809765 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/37809765 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/37809765 Branch: refs/heads/master Commit: 3780976576ed6fcd458edaec94e9a633b9fa3551 Parents: 33105af Author: Tibor17 <tibo...@lycos.com> Authored: Sun Dec 27 19:10:52 2015 +0100 Committer: Tibor17 <tibo...@lycos.com> Committed: Sun Dec 27 19:10:52 2015 +0100 ---------------------------------------------------------------------- .../maven/plugin/failsafe/VerifyMojo.java | 2 +- .../plugin/surefire/AbstractSurefireMojo.java | 86 ++++++++++---------- .../plugin/surefire/SurefireProperties.java | 17 ++-- .../booterclient/ForkConfiguration.java | 15 ++-- .../apache/maven/surefire/booter/Shutdown.java | 8 +- .../surefire/testset/TestListResolver.java | 14 ++-- .../apache/maven/surefire/util/RunOrder.java | 14 ++-- .../apache/maven/surefire/util/TestsToRun.java | 10 +-- .../surefire/report/SmartStackTraceParser.java | 28 +++---- .../surefire/common/junit48/AndFilter.java | 8 +- .../maven/surefire/common/junit48/OrFilter.java | 8 +- .../maven/surefire/junitcore/TestSet.java | 16 ++-- .../testng/conf/AbstractDirectConfigurator.java | 2 +- 13 files changed, 115 insertions(+), 113 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java ---------------------------------------------------------------------- diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java index ab176d6..021fcb6 100644 --- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java +++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java @@ -154,7 +154,7 @@ public class VerifyMojo * The current build session instance. */ @Component - protected MavenSession session; + private MavenSession session; private Collection<CommandLineOption> cli; http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index 2654e2e..0a81557 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -117,7 +117,7 @@ public abstract class AbstractSurefireMojo * @since 2.12 */ @Parameter( defaultValue = "${plugin}", readonly = true ) - protected PluginDescriptor pluginDescriptor; + private PluginDescriptor pluginDescriptor; /** * Set this to "true" to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite @@ -149,7 +149,7 @@ public abstract class AbstractSurefireMojo * The Maven Project Object. */ @Component - protected MavenProject project; + private MavenProject project; /** * The base directory of the project being tested. This can be obtained in your integration test via @@ -205,7 +205,7 @@ public abstract class AbstractSurefireMojo * @since 2.2 */ @Parameter( defaultValue = "${project.build.testSourceDirectory}", required = true ) - protected File testSourceDirectory; + private File testSourceDirectory; /** * A list of <exclude> elements specifying the tests (by pattern) that should be excluded in testing. When not @@ -227,14 +227,14 @@ public abstract class AbstractSurefireMojo * unless overridden. */ @Parameter - protected List<String> excludes; + private List<String> excludes; /** * ArtifactRepository of the localRepository. To obtain the directory of localRepository in unit tests use * System.getProperty("localRepository"). */ @Parameter( defaultValue = "${localRepository}", required = true, readonly = true ) - protected ArtifactRepository localRepository; + private ArtifactRepository localRepository; /** * List of System properties to pass to the JUnit tests. @@ -242,7 +242,7 @@ public abstract class AbstractSurefireMojo * @deprecated Use systemPropertyVariables instead. */ @Parameter - protected Properties systemProperties; + private Properties systemProperties; /** * List of System properties to pass to the JUnit tests. @@ -250,7 +250,7 @@ public abstract class AbstractSurefireMojo * @since 2.5 */ @Parameter - protected Map<String, String> systemPropertyVariables; + private Map<String, String> systemPropertyVariables; /** * List of System properties, loaded from a file, to pass to the JUnit tests. @@ -258,7 +258,7 @@ public abstract class AbstractSurefireMojo * @since 2.8.2 */ @Parameter - protected File systemPropertiesFile; + private File systemPropertiesFile; /** * List of properties for configuring all TestNG related configurations. This is the new preferred method of @@ -267,21 +267,21 @@ public abstract class AbstractSurefireMojo * @since 2.4 */ @Parameter - protected Properties properties; + private Properties properties; /** * Map of plugin artifacts. */ // olamy: would make more sense using defaultValue but doesn't work with maven 2.x @Parameter( property = "plugin.artifactMap", required = true, readonly = true ) - protected Map<String, Artifact> pluginArtifactMap; + private Map<String, Artifact> pluginArtifactMap; /** * Map of project artifacts. */ // olamy: would make more sense using defaultValue but doesn't work with maven 2.x @Parameter( property = "project.artifactMap", readonly = true, required = true ) - protected Map<String, Artifact> projectArtifactMap; + private Map<String, Artifact> projectArtifactMap; /** * Add custom text into report filename: TEST-testClassName-reportNameSuffix.xml, @@ -290,7 +290,7 @@ public abstract class AbstractSurefireMojo * and 'testcase'--'classname' - reportNameSuffix is added to the attribute value. */ @Parameter( property = "surefire.reportNameSuffix", defaultValue = "" ) - protected String reportNameSuffix; + private String reportNameSuffix; /** * Set this to "true" to redirect the unit test standard output to a file (found in @@ -299,7 +299,7 @@ public abstract class AbstractSurefireMojo * @since 2.3 */ @Parameter( property = "maven.test.redirectTestOutputToFile", defaultValue = "false" ) - protected boolean redirectTestOutputToFile; + private boolean redirectTestOutputToFile; /** * Set this to "true" to cause a failure if there are no tests to run. Defaults to "false". @@ -307,7 +307,7 @@ public abstract class AbstractSurefireMojo * @since 2.4 */ @Parameter( property = "failIfNoTests" ) - protected Boolean failIfNoTests; + private Boolean failIfNoTests; /** * <strong>DEPRECATED</strong> since version 2.14. Use <code>forkCount</code> and <code>reuseForks</code> instead. @@ -321,7 +321,7 @@ public abstract class AbstractSurefireMojo * @since 2.1 */ @Parameter( property = "forkMode", defaultValue = "once" ) - protected String forkMode; + private String forkMode; /** * Option to specify the jvm (or path to the java executable) to use with the forking options. For the default, the @@ -331,7 +331,7 @@ public abstract class AbstractSurefireMojo * @since 2.1 */ @Parameter( property = "jvm" ) - protected String jvm; + private String jvm; /** * Arbitrary JVM options to set on the command line. @@ -349,7 +349,7 @@ public abstract class AbstractSurefireMojo * @since 2.1 */ @Parameter( property = "argLine" ) - protected String argLine; + private String argLine; /** * Additional environment variables to set on the command line. @@ -357,7 +357,7 @@ public abstract class AbstractSurefireMojo * @since 2.1.3 */ @Parameter - protected Map<String, String> environmentVariables = new HashMap<String, String>(); + private Map<String, String> environmentVariables = new HashMap<String, String>(); /** * Command line working directory. @@ -365,7 +365,7 @@ public abstract class AbstractSurefireMojo * @since 2.1.3 */ @Parameter( property = "basedir" ) - protected File workingDirectory; + private File workingDirectory; /** * When false it makes tests run using the standard classloader delegation instead of the default Maven isolated @@ -376,7 +376,7 @@ public abstract class AbstractSurefireMojo * @since 2.1 */ @Parameter( property = "childDelegation", defaultValue = "false" ) - protected boolean childDelegation; + private boolean childDelegation; /** * (TestNG/JUnit47 provider with JUnit4.8+ only) Groups for this test. Only classes/methods/etc decorated with one @@ -390,7 +390,7 @@ public abstract class AbstractSurefireMojo * @since 2.2 */ @Parameter( property = "groups" ) - protected String groups; + private String groups; /** * (TestNG/JUnit47 provider with JUnit4.8+ only) Excluded groups. Any methods/classes/etc with one of the groups @@ -404,7 +404,7 @@ public abstract class AbstractSurefireMojo * @since 2.2 */ @Parameter( property = "excludedGroups" ) - protected String excludedGroups; + private String excludedGroups; /** * Allows you to specify the name of the JUnit artifact. If not set, <code>junit:junit</code> will be used. @@ -412,7 +412,7 @@ public abstract class AbstractSurefireMojo * @since 2.3.1 */ @Parameter( property = "junitArtifactName", defaultValue = "junit:junit" ) - protected String junitArtifactName; + private String junitArtifactName; /** * Allows you to specify the name of the TestNG artifact. If not set, <code>org.testng:testng</code> will be used. @@ -420,7 +420,7 @@ public abstract class AbstractSurefireMojo * @since 2.3.1 */ @Parameter( property = "testNGArtifactName", defaultValue = "org.testng:testng" ) - protected String testNGArtifactName; + private String testNGArtifactName; /** * (TestNG/JUnit 4.7 provider) The attribute thread-count allows you to specify how many threads should be @@ -429,7 +429,7 @@ public abstract class AbstractSurefireMojo * @since 2.2 */ @Parameter( property = "threadCount" ) - protected int threadCount; + private int threadCount; /** * Option to specify the number of VMs to fork in parallel in order to execute the tests. When terminated with "C", @@ -466,7 +466,7 @@ public abstract class AbstractSurefireMojo * @since 2.5 */ @Parameter( property = "perCoreThreadCount", defaultValue = "true" ) - protected boolean perCoreThreadCount; + private boolean perCoreThreadCount; /** * (JUnit 4.7 provider) Indicates that the thread pool will be unlimited. The <code>parallel</code> parameter and @@ -476,7 +476,7 @@ public abstract class AbstractSurefireMojo * @since 2.5 */ @Parameter( property = "useUnlimitedThreads", defaultValue = "false" ) - protected boolean useUnlimitedThreads; + private boolean useUnlimitedThreads; /** * (TestNG provider) When you use the <code>parallel</code> attribute, TestNG will try to run all your test methods @@ -495,7 +495,7 @@ public abstract class AbstractSurefireMojo * @since 2.2 */ @Parameter( property = "parallel" ) - protected String parallel; + private String parallel; /** * (JUnit 4.7 / provider only) The thread counts do not exceed the number of parallel suite, class runners and @@ -506,7 +506,7 @@ public abstract class AbstractSurefireMojo * @since 2.17 */ @Parameter( property = "parallelOptimized", defaultValue = "true" ) - protected boolean parallelOptimized; + private boolean parallelOptimized; /** * (JUnit 4.7 provider) This attribute allows you to specify the concurrency in test suites, i.e.: @@ -525,7 +525,7 @@ public abstract class AbstractSurefireMojo * @since 2.16 */ @Parameter( property = "threadCountSuites", defaultValue = "0" ) - protected int threadCountSuites; + private int threadCountSuites; /** * (JUnit 4.7 provider) This attribute allows you to specify the concurrency in test classes, i.e.: @@ -548,7 +548,7 @@ public abstract class AbstractSurefireMojo * @since 2.16 */ @Parameter( property = "threadCountClasses", defaultValue = "0" ) - protected int threadCountClasses; + private int threadCountClasses; /** * (JUnit 4.7 provider) This attribute allows you to specify the concurrency in test methods, i.e.: @@ -570,7 +570,7 @@ public abstract class AbstractSurefireMojo * @since 2.16 */ @Parameter( property = "threadCountMethods", defaultValue = "0" ) - protected int threadCountMethods; + private int threadCountMethods; /** * Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace. @@ -578,19 +578,19 @@ public abstract class AbstractSurefireMojo * @since 2.2 */ @Parameter( property = "trimStackTrace", defaultValue = "true" ) - protected boolean trimStackTrace; + private boolean trimStackTrace; /** * Resolves the artifacts needed. */ @Component - protected ArtifactResolver artifactResolver; + private ArtifactResolver artifactResolver; /** * Creates the artifact. */ @Component - protected ArtifactFactory artifactFactory; + private ArtifactFactory artifactFactory; /** * The remote plugin repositories declared in the POM. @@ -598,13 +598,13 @@ public abstract class AbstractSurefireMojo * @since 2.2 */ @Parameter( defaultValue = "${project.pluginArtifactRepositories}" ) - protected List<ArtifactRepository> remoteRepositories; + private List<ArtifactRepository> remoteRepositories; /** * For retrieval of artifact's metadata. */ @Component - protected ArtifactMetadataSource metadataSource; + private ArtifactMetadataSource metadataSource; /** * Flag to disable the generation of report files in xml format. @@ -612,7 +612,7 @@ public abstract class AbstractSurefireMojo * @since 2.2 */ @Parameter( property = "disableXmlReport", defaultValue = "false" ) - protected boolean disableXmlReport; + private boolean disableXmlReport; /** * By default, Surefire enables JVM assertions for the execution of your test cases. To disable the assertions, set @@ -621,13 +621,13 @@ public abstract class AbstractSurefireMojo * @since 2.3.1 */ @Parameter( property = "enableAssertions", defaultValue = "true" ) - protected boolean enableAssertions; + private boolean enableAssertions; /** * The current build session instance. */ @Component - protected MavenSession session; + private MavenSession session; /** * (TestNG only) Define the factory class used to create all test instances. @@ -635,13 +635,13 @@ public abstract class AbstractSurefireMojo * @since 2.5 */ @Parameter( property = "objectFactory" ) - protected String objectFactory; + private String objectFactory; /** * */ @Parameter( defaultValue = "${session.parallel}", readonly = true ) - protected Boolean parallelMavenExecution; + private Boolean parallelMavenExecution; /** * List of dependencies to scan for test classes to include in the test run. @@ -659,7 +659,7 @@ public abstract class AbstractSurefireMojo * */ @Component - protected ToolchainManager toolchainManager; + private ToolchainManager toolchainManager; private Artifact surefireBooterArtifact; http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java index d41d4d7..b1537d6 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java @@ -23,7 +23,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; @@ -37,6 +37,8 @@ import org.apache.maven.surefire.booter.Classpath; import org.apache.maven.surefire.booter.KeyValueSource; import org.apache.maven.surefire.util.internal.StringUtils; +import static java.util.Arrays.asList; + /** * A properties implementation that preserves insertion order. */ @@ -44,6 +46,9 @@ public class SurefireProperties extends Properties implements KeyValueSource { + private static final Collection<String> KEYS_THAT_CANNOT_BE_USED_AS_SYSTEM_PROPERTIES = + asList( "java.library.path", "file.encoding", "jdk.map.althashing.threshold" ); + private final LinkedHashSet<Object> items = new LinkedHashSet<Object>(); public SurefireProperties() @@ -96,12 +101,7 @@ public class SurefireProperties { if ( source != null ) { - //noinspection unchecked - for ( Object key : source.keySet() ) - { - Object value = source.get( key ); - put( key, value ); - } + putAll( source ); } } @@ -111,9 +111,6 @@ public class SurefireProperties return keySet(); } - private static final Set<String> KEYS_THAT_CANNOT_BE_USED_AS_SYSTEM_PROPERTIES = new HashSet<String>( - Arrays.asList( "java.library.path", "file.encoding", "jdk.map.althashing.threshold" ) ); - public Set<Object> propertiesThatCannotBeSetASystemProperties() { Set<Object> result = new HashSet<Object>(); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java index 1477e87..036ec56 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java @@ -161,12 +161,10 @@ public class ForkConfiguration if ( environmentVariables != null ) { - - for ( String key : environmentVariables.keySet() ) + for ( Map.Entry<String, String> entry : environmentVariables.entrySet() ) { - String value = environmentVariables.get( key ); - - cli.addEnvironment( key, value == null ? "" : value ); + String value = entry.getValue(); + cli.addEnvironment( entry.getKey(), value == null ? "" : value ); } } @@ -285,15 +283,16 @@ public class ForkConfiguration // we can't use StringUtils.join here since we need to add a '/' to // the end of directory entries - otherwise the jvm will ignore them. - String cp = ""; + StringBuilder cp = new StringBuilder(); for ( String el : classPath ) { // NOTE: if File points to a directory, this entry MUST end in '/'. - cp += UrlUtils.getURL( new File( el ) ).toExternalForm() + " "; + cp.append( UrlUtils.getURL( new File( el ) ).toExternalForm() ) + .append( " " ); } man.getMainAttributes().putValue( "Manifest-Version", "1.0" ); - man.getMainAttributes().putValue( "Class-Path", cp.trim() ); + man.getMainAttributes().putValue( "Class-Path", cp.toString().trim() ); man.getMainAttributes().putValue( "Main-Class", startClassName ); man.write( jos ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-api/src/main/java/org/apache/maven/surefire/booter/Shutdown.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/Shutdown.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/Shutdown.java index 660a40e..262cb29 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/Shutdown.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/Shutdown.java @@ -58,16 +58,16 @@ public enum Shutdown public static String listParameters() { - String values = ""; + StringBuilder values = new StringBuilder(); for ( Shutdown shutdown : values() ) { if ( values.length() != 0 ) { - values += ", "; + values.append( ", " ); } - values += shutdown.getParam(); + values.append( shutdown.getParam() ); } - return values; + return values.toString(); } public static Shutdown parameterOf( String parameter ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java b/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java index ce80c4e..68de091 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestListResolver.java @@ -326,17 +326,21 @@ public class TestListResolver private static String aggregatedTest( String testPrefix, Set<ResolvedTest> tests ) { - String aggregatedTest = ""; + StringBuilder aggregatedTest = new StringBuilder(); for ( ResolvedTest test : tests ) { String readableTest = test.toString(); - if ( aggregatedTest.length() != 0 && readableTest != null ) + if ( readableTest != null ) { - aggregatedTest += ", "; + if ( aggregatedTest.length() != 0 ) + { + aggregatedTest.append( ", " ); + } + aggregatedTest.append( testPrefix ) + .append( readableTest ); } - aggregatedTest += testPrefix + readableTest; } - return aggregatedTest; + return aggregatedTest.toString(); } private static Collection<String> mergeIncludedAndExcludedTests( Collection<String> included, http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java index 4647172..ebbec70 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/RunOrder.java @@ -91,19 +91,19 @@ public class RunOrder private static String createMessageForMissingRunOrder( String name ) { RunOrder[] runOrders = values(); - String message = "There's no RunOrder with the name "; - message += name; - message += ". Please use one of the following RunOrders: "; + StringBuilder message = new StringBuilder( "There's no RunOrder with the name " ); + message.append( name ); + message.append( ". Please use one of the following RunOrders: " ); for ( int i = 0; i < runOrders.length; i++ ) { if ( i != 0 ) { - message += ", "; + message.append( ", " ); } - message += runOrders[i]; + message.append( runOrders[i] ); } - message += "."; - return message; + message.append( '.' ); + return message.toString(); } private static RunOrder[] values() http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java index 3b5ef22..204bed8 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java @@ -129,15 +129,15 @@ public class TestsToRun implements Iterable<Class<?>> public String toString() { - String sb = "TestsToRun: ["; + StringBuilder sb = new StringBuilder( "TestsToRun: [" ); for ( Class<?> clazz : this ) { - sb += " "; - sb += clazz.getName(); + sb.append( ' ' ) + .append( clazz.getName() ); } - sb += ']'; - return sb; + sb.append( ']' ); + return sb.toString(); } public boolean containsAtLeast( int atLeast ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java b/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java index 8ad2369..7c68f95 100644 --- a/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java +++ b/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java @@ -277,46 +277,46 @@ public class SmartStackTraceParser private static String causeToString( Throwable cause, StackTraceFilter filter ) { - String resp = ""; + StringBuilder resp = new StringBuilder(); while ( cause != null ) { - resp += "Caused by: "; - resp += toString( cause, asList( cause.getStackTrace() ), filter ); + resp.append( "Caused by: " ); + resp.append( toString( cause, asList( cause.getStackTrace() ), filter ) ); cause = cause.getCause(); } - return resp; + return resp.toString(); } private static String toString( Throwable t, Iterable<StackTraceElement> elements, StackTraceFilter filter ) { - String result = ""; + StringBuilder result = new StringBuilder(); if ( t != null ) { - result += t.getClass().getName(); + result.append( t.getClass().getName() ); String msg = t.getMessage(); if ( msg != null ) { - result += ": "; + result.append( ": " ); if ( isMultiLine( msg ) ) { // SUREFIRE-986 - result += "\n"; + result.append( '\n' ); } - result += msg; + result.append( msg ); } - result += "\n"; + result.append( '\n' ); } for ( StackTraceElement element : elements ) { if ( filter.matches( element ) ) { - result += "\tat "; - result += element; - result += "\n"; + result.append( "\tat " ) + .append( element ) + .append( '\n' ); } } - return result; + return result.toString(); } private static boolean isMultiLine( String msg ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java index 4368434..2890895 100644 --- a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java @@ -48,15 +48,15 @@ final class AndFilter @Override public String describe() { - String description = ""; + StringBuilder description = new StringBuilder(); for ( int i = 0; i < filters.length; i++ ) { - description += filters[i].describe(); + description.append( filters[i].describe() ); if ( i != filters.length - 1 ) { - description += " AND "; + description.append( " AND " ); } } - return description; + return description.toString(); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java index b5b2b56..0b9feab 100644 --- a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java @@ -48,15 +48,15 @@ final class OrFilter @Override public String describe() { - String description = ""; + StringBuilder description = new StringBuilder(); for ( int i = 0; i < filters.length; i++ ) { - description += filters[i].describe(); + description.append( filters[i].describe() ); if ( i != filters.length - 1 ) { - description += " OR "; + description.append( " OR " ); } } - return description; + return description.toString(); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java index d7a6a01..d7bb722 100644 --- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java +++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java @@ -23,6 +23,8 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + import org.apache.maven.surefire.report.ReportEntry; import org.apache.maven.surefire.report.RunListener; import org.apache.maven.surefire.report.SimpleReportEntry; @@ -42,14 +44,14 @@ public class TestSet private final AtomicBoolean played = new AtomicBoolean(); - private volatile boolean allScheduled; - - private volatile int numberOfCompletedChildren; + private final AtomicInteger numberOfCompletedChildren = new AtomicInteger(); // While the two parameters may seem duplicated, it is not entirely the case, // since numberOfTests has the correct value from the start, while testMethods grows as method execution starts. - private volatile int numberOfTests; + private final AtomicInteger numberOfTests = new AtomicInteger(); + + private volatile boolean allScheduled; public TestSet( Description testSetDescription ) { @@ -123,7 +125,7 @@ public class TestSet public void incrementTestMethodCount() { - numberOfTests++; + numberOfTests.incrementAndGet(); } private void addTestMethod( TestMethod testMethod ) @@ -133,7 +135,7 @@ public class TestSet public void incrementFinishedTests( RunListener reporterManager, boolean reportImmediately ) { - numberOfCompletedChildren++; + numberOfCompletedChildren.incrementAndGet(); if ( allScheduled && isAllTestsDone() && reportImmediately ) { replay( reporterManager ); @@ -151,7 +153,7 @@ public class TestSet private boolean isAllTestsDone() { - return numberOfTests == numberOfCompletedChildren; + return numberOfTests.get() == numberOfCompletedChildren.get(); } public void attachToThread() http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/37809765/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java index a9cdc50..e89d061 100644 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java @@ -184,7 +184,7 @@ public abstract class AbstractDirectConfigurator } if ( Integer.class.equals( paramClass ) || int.class.equals( paramClass ) ) { - return new Integer( value ); + return Integer.valueOf( value ); } return value;