You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2016/02/01 00:04:55 UTC
maven-surefire git commit: [SUREFIRE-1224] Improve Code Quality After
Sonar Report
Repository: maven-surefire
Updated Branches:
refs/heads/master 1e71470b3 -> eaf25fa03
[SUREFIRE-1224] Improve Code Quality 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/eaf25fa0
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/eaf25fa0
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/eaf25fa0
Branch: refs/heads/master
Commit: eaf25fa03c44d2a813d3bdaa27e08a76ad1f87b2
Parents: 1e71470
Author: Tibor17 <ti...@lycos.com>
Authored: Mon Feb 1 00:04:38 2016 +0100
Committer: Tibor17 <ti...@lycos.com>
Committed: Mon Feb 1 00:04:38 2016 +0100
----------------------------------------------------------------------
.../maven/plugin/surefire/SurefireHelper.java | 26 ++--
.../surefire/report/DefaultReporterFactory.java | 8 +-
.../maven/surefire/testset/ResolvedTest.java | 104 ++++++++-----
.../surefire/testset/TestListResolver.java | 2 +-
.../surefire/testset/ResolvedTestTest.java | 20 ++-
.../apache/maven/surefire/booter/Classpath.java | 14 +-
.../surefire/booter/IsolatedClassLoader.java | 29 ++--
.../surefire/booter/PropertiesWrapper.java | 1 -
.../maven/surefire/booter/TypeEncodedValue.java | 38 +++--
.../junit48/GroupMatcherCategoryFilter.java | 17 +-
.../surefire/common/junit48/RequestedTest.java | 2 +-
.../maven/surefire/junit/PojoTestSet.java | 11 +-
.../junitcore/pc/ParallelComputerBuilder.java | 79 +++++++---
.../pc/ParallelComputerBuilderTest.java | 154 +++++++++----------
.../testng/conf/TestNGMapConfigurator.java | 37 +++--
.../surefire/report/TestSuiteXmlParser.java | 2 +
16 files changed, 321 insertions(+), 223 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java
index a4319bc..3b0bbc2 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java
@@ -31,9 +31,15 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
+import static java.util.Collections.unmodifiableList;
+import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_ERROR;
+import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_WARN;
+import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_INFO;
+import static org.apache.maven.surefire.cli.CommandLineOption.LOGGING_LEVEL_DEBUG;
+import static org.apache.maven.surefire.cli.CommandLineOption.SHOW_ERRORS;
+
/**
* Helper class for surefire plugins
*/
@@ -57,7 +63,7 @@ public final class SurefireHelper
{
if ( result.getCompletedCount() == 0 )
{
- if ( ( reportParameters.getFailIfNoTests() == null ) || !reportParameters.getFailIfNoTests() )
+ if ( reportParameters.getFailIfNoTests() == null || !reportParameters.getFailIfNoTests() )
{
return;
}
@@ -98,22 +104,22 @@ public final class SurefireHelper
List<CommandLineOption> cli = new ArrayList<CommandLineOption>();
if ( log.isErrorEnabled() )
{
- cli.add( CommandLineOption.LOGGING_LEVEL_ERROR );
+ cli.add( LOGGING_LEVEL_ERROR );
}
if ( log.isWarnEnabled() )
{
- cli.add( CommandLineOption.LOGGING_LEVEL_WARN );
+ cli.add( LOGGING_LEVEL_WARN );
}
if ( log.isInfoEnabled() )
{
- cli.add( CommandLineOption.LOGGING_LEVEL_INFO );
+ cli.add( LOGGING_LEVEL_INFO );
}
if ( log.isDebugEnabled() )
{
- cli.add( CommandLineOption.LOGGING_LEVEL_DEBUG );
+ cli.add( LOGGING_LEVEL_DEBUG );
}
try
@@ -130,23 +136,23 @@ public final class SurefireHelper
if ( request.isShowErrors() )
{
- cli.add( CommandLineOption.SHOW_ERRORS );
+ cli.add( SHOW_ERRORS );
}
}
catch ( Exception e )
{
// don't need to log the exception that Maven 2 does not have getRequest() method in Maven Session
}
- return Collections.unmodifiableList( cli );
+ return unmodifiableList( cli );
}
public static void logDebugOrCliShowErrors( CharSequence s, Log log, Collection<CommandLineOption> cli )
{
- if ( cli.contains( CommandLineOption.LOGGING_LEVEL_DEBUG ) )
+ if ( cli.contains( LOGGING_LEVEL_DEBUG ) )
{
log.debug( s );
}
- else if ( cli.contains( CommandLineOption.SHOW_ERRORS ) )
+ else if ( cli.contains( SHOW_ERRORS ) )
{
if ( log.isDebugEnabled() )
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
index c28bed2..0a4aa54 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
@@ -317,7 +317,6 @@ public class DefaultReporterFactory
// Use default visibility for testing
boolean printTestFailures( DefaultDirectConsoleReporter logger, TestResultType type )
{
- boolean printed = false;
final Map<String, List<TestMethodStats>> testStats;
switch ( type )
{
@@ -331,9 +330,10 @@ public class DefaultReporterFactory
testStats = flakyTests;
break;
default:
- return printed;
+ return false;
}
+ boolean printed = false;
if ( !testStats.isEmpty() )
{
logger.info( type.getLogPrefix() );
@@ -371,7 +371,7 @@ public class DefaultReporterFactory
}
// Describe the result of a given test
- static enum TestResultType
+ enum TestResultType
{
error( "Tests in error: " ),
@@ -383,7 +383,7 @@ public class DefaultReporterFactory
private final String logPrefix;
- private TestResultType( String logPrefix )
+ TestResultType( String logPrefix )
{
this.logPrefix = logPrefix;
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java b/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java
index 74c11e2..cf3af6f 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/testset/ResolvedTest.java
@@ -20,30 +20,32 @@ package org.apache.maven.surefire.testset;
*/
import org.apache.maven.shared.utils.StringUtils;
-import org.apache.maven.shared.utils.io.MatchPatterns;
-import org.apache.maven.shared.utils.io.SelectorUtils;
-import java.io.File;
+import static java.io.File.separatorChar;
+import static org.apache.maven.shared.utils.StringUtils.isBlank;
+import static org.apache.maven.shared.utils.io.MatchPatterns.from;
+import static org.apache.maven.shared.utils.io.SelectorUtils.PATTERN_HANDLER_SUFFIX;
+import static org.apache.maven.shared.utils.io.SelectorUtils.REGEX_HANDLER_PREFIX;
+import static org.apache.maven.shared.utils.io.SelectorUtils.matchPath;
/**
* Single pattern test filter resolved from multi pattern filter -Dtest=MyTest#test,AnotherTest#otherTest.
* @deprecated will be renamed to ResolvedTestPattern
*/
-@Deprecated // will be renamed to ResolvedTestPattern
+// will be renamed to ResolvedTestPattern
+@Deprecated
public final class ResolvedTest
{
/**
* Type of patterns in ResolvedTest constructor.
*/
- public static enum Type
+ public enum Type
{
CLASS, METHOD
}
private static final String CLASS_FILE_EXTENSION = ".class";
- private static final String WILDCARD_CLASS_FILE_EXTENSION = ".class";
-
private static final String JAVA_FILE_EXTENSION = ".java";
private static final String WILDCARD_PATH_PREFIX = "**/";
@@ -205,7 +207,7 @@ public final class ResolvedTest
@Override
public String toString()
{
- return isEmpty() ? null : description;
+ return isEmpty() ? "" : description;
}
private static String description( String clazz, String method, boolean isRegex )
@@ -232,9 +234,24 @@ public final class ResolvedTest
private boolean canMatchExclusive( String testClassFile, String methodName )
{
- return testClassFile == null && methodName != null && classPattern == null && methodPattern != null
- || testClassFile != null && methodName == null && classPattern != null && methodPattern == null
- || testClassFile != null && methodName != null && ( classPattern != null || methodPattern != null );
+ return canMatchExclusiveMethods( testClassFile, methodName )
+ || canMatchExclusiveClasses( testClassFile, methodName )
+ || canMatchExclusiveAll( testClassFile, methodName );
+ }
+
+ private boolean canMatchExclusiveMethods( String testClassFile, String methodName )
+ {
+ return testClassFile == null && methodName != null && classPattern == null && methodPattern != null;
+ }
+
+ private boolean canMatchExclusiveClasses( String testClassFile, String methodName )
+ {
+ return testClassFile != null && methodName == null && classPattern != null && methodPattern == null;
+ }
+
+ private boolean canMatchExclusiveAll( String testClassFile, String methodName )
+ {
+ return testClassFile != null && methodName != null && ( classPattern != null || methodPattern != null );
}
/**
@@ -247,8 +264,17 @@ public final class ResolvedTest
private boolean match( String testClassFile, String methodName )
{
- return ( classPattern == null || matchTestClassFile( testClassFile ) )
- && ( methodPattern == null || methodName == null || matchMethodName( methodName ) );
+ return matchClass( testClassFile ) && matchMethod( methodName );
+ }
+
+ private boolean matchClass( String testClassFile )
+ {
+ return classPattern == null || matchTestClassFile( testClassFile );
+ }
+
+ private boolean matchMethod( String methodName )
+ {
+ return methodPattern == null || methodName == null || matchMethodName( methodName );
}
private boolean matchTestClassFile( String testClassFile )
@@ -258,37 +284,34 @@ public final class ResolvedTest
private boolean matchMethodName( String methodName )
{
- return SelectorUtils.matchPath( methodPattern, methodName );
+ return matchPath( methodPattern, methodName );
}
private boolean matchClassPatter( String testClassFile )
{
//@todo We have to use File.separator only because the MatchPatterns is using it internally - cannot override.
String classPattern = this.classPattern;
- if ( File.separatorChar != '/' )
+ if ( separatorChar != '/' )
{
- testClassFile = testClassFile.replace( '/', File.separatorChar );
- classPattern = classPattern.replace( '/', File.separatorChar );
+ testClassFile = testClassFile.replace( '/', separatorChar );
+ classPattern = classPattern.replace( '/', separatorChar );
}
if ( classPattern.endsWith( WILDCARD_FILENAME_POSTFIX ) || classPattern.endsWith( CLASS_FILE_EXTENSION ) )
{
- return MatchPatterns.from( classPattern ).matches( testClassFile, true );
+ return from( classPattern ).matches( testClassFile, true );
}
else
{
String[] classPatterns = { classPattern + CLASS_FILE_EXTENSION, classPattern };
- return MatchPatterns.from( classPatterns ).matches( testClassFile, true );
+ return from( classPatterns ).matches( testClassFile, true );
}
}
private boolean matchClassRegexPatter( String testClassFile )
{
- if ( File.separatorChar != '/' )
- {
- testClassFile = testClassFile.replace( '/', File.separatorChar );
- }
- return MatchPatterns.from( classPattern ).matches( testClassFile, true );
+ String realFile = separatorChar == '/' ? testClassFile : testClassFile.replace( '/', separatorChar );
+ return from( classPattern ).matches( realFile, true );
}
private static String tryBlank( String s )
@@ -299,8 +322,8 @@ public final class ResolvedTest
}
else
{
- s = s.trim();
- return StringUtils.isEmpty( s ) ? null : s;
+ String trimmed = s.trim();
+ return StringUtils.isEmpty( trimmed ) ? null : trimmed;
}
}
@@ -308,19 +331,23 @@ public final class ResolvedTest
{
if ( s != null && !isRegex )
{
- s = convertToPath( s );
- s = fromFullyQualifiedClass( s );
- if ( s != null && !s.startsWith( WILDCARD_PATH_PREFIX ) )
+ String path = convertToPath( s );
+ path = fromFullyQualifiedClass( path );
+ if ( path != null && !path.startsWith( WILDCARD_PATH_PREFIX ) )
{
- s = WILDCARD_PATH_PREFIX + s;
+ path = WILDCARD_PATH_PREFIX + path;
}
+ return path;
+ }
+ else
+ {
+ return s;
}
- return s;
}
private static String convertToPath( String className )
{
- if ( StringUtils.isBlank( className ) )
+ if ( isBlank( className ) )
{
return null;
}
@@ -337,23 +364,22 @@ public final class ResolvedTest
static String wrapRegex( String unwrapped )
{
- return SelectorUtils.REGEX_HANDLER_PREFIX + unwrapped + SelectorUtils.PATTERN_HANDLER_SUFFIX;
+ return REGEX_HANDLER_PREFIX + unwrapped + PATTERN_HANDLER_SUFFIX;
}
static String fromFullyQualifiedClass( String cls )
{
if ( cls.endsWith( CLASS_FILE_EXTENSION ) )
{
- cls = cls.substring( 0, cls.length() - CLASS_FILE_EXTENSION.length() );
- return cls.replace( '.', '/' ) + CLASS_FILE_EXTENSION;
+ String className = cls.substring( 0, cls.length() - CLASS_FILE_EXTENSION.length() );
+ return className.replace( '.', '/' ) + CLASS_FILE_EXTENSION;
}
else if ( !cls.contains( "/" ) )
{
- if ( cls.endsWith( WILDCARD_CLASS_FILE_EXTENSION ) )
+ if ( cls.endsWith( WILDCARD_FILENAME_POSTFIX ) )
{
- String origin = cls;
- cls = cls.substring( 0, cls.length() - WILDCARD_CLASS_FILE_EXTENSION.length() );
- return cls.contains( "." ) ? cls.replace( '.', '/' ) + WILDCARD_CLASS_FILE_EXTENSION : origin;
+ String clsName = cls.substring( 0, cls.length() - WILDCARD_FILENAME_POSTFIX.length() );
+ return clsName.contains( "." ) ? clsName.replace( '.', '/' ) + WILDCARD_FILENAME_POSTFIX : cls;
}
else
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/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 68de091..fc21425 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
@@ -330,7 +330,7 @@ public class TestListResolver
for ( ResolvedTest test : tests )
{
String readableTest = test.toString();
- if ( readableTest != null )
+ if ( readableTest.length() != 0 )
{
if ( aggregatedTest.length() != 0 )
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java
index 95cc812..f636c72 100644
--- a/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java
+++ b/surefire-api/src/test/java/org/apache/maven/surefire/testset/ResolvedTestTest.java
@@ -20,12 +20,16 @@ package org.apache.maven.surefire.testset;
import junit.framework.TestCase;
+import static org.apache.maven.surefire.testset.ResolvedTest.Type.CLASS;
+import static org.apache.maven.surefire.testset.ResolvedTest.Type.METHOD;
+import static org.apache.maven.surefire.testset.ResolvedTest.fromFullyQualifiedClass;
+
public class ResolvedTestTest
extends TestCase
{
public void testEmptyClassRegex()
{
- ResolvedTest test = new ResolvedTest( ResolvedTest.Type.CLASS, " ", true );
+ ResolvedTest test = new ResolvedTest( CLASS, " ", true );
assertNull( test.getTestClassPattern() );
assertNull( test.getTestMethodPattern() );
assertFalse( test.hasTestClassPattern() );
@@ -37,7 +41,7 @@ public class ResolvedTestTest
public void testEmptyMethodRegex()
{
- ResolvedTest test = new ResolvedTest( ResolvedTest.Type.METHOD, " ", true );
+ ResolvedTest test = new ResolvedTest( METHOD, " ", true );
assertNull( test.getTestClassPattern() );
assertNull( test.getTestMethodPattern() );
assertFalse( test.hasTestClassPattern() );
@@ -49,13 +53,19 @@ public class ResolvedTestTest
public void testFromFullyQualifiedClass()
{
- String classFileName = ResolvedTest.fromFullyQualifiedClass( "my.package.MyTest" );
+ String classFileName = fromFullyQualifiedClass("my.package.MyTest");
assertEquals( "my/package/MyTest", classFileName );
- classFileName = ResolvedTest.fromFullyQualifiedClass( "my.package.MyTest.class" );
+ classFileName = fromFullyQualifiedClass("my.package.MyTest.class");
assertEquals( "my/package/MyTest.class", classFileName );
- classFileName = ResolvedTest.fromFullyQualifiedClass( "my/package/MyTest.class" );
+ classFileName = fromFullyQualifiedClass("my/package/MyTest.class");
assertEquals( "my/package/MyTest.class", classFileName );
+
+ classFileName = fromFullyQualifiedClass("my/package/MyTest.*");
+ assertEquals( "my/package/MyTest.*", classFileName );
+
+ classFileName = fromFullyQualifiedClass("my.package.MyTest.*");
+ assertEquals( "my/package/MyTest.*", classFileName );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
index a2a3d52..d03fed1 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
@@ -31,6 +31,8 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
+import static java.io.File.pathSeparatorChar;
+
/**
* An ordered list of classpath elements with set behaviour
*
@@ -42,7 +44,6 @@ import java.util.List;
*/
public class Classpath implements Iterable<String>
{
-
private final List<String> unmodifiableElements;
public static Classpath join( Classpath firstClasspath, Classpath secondClasspath )
@@ -111,6 +112,11 @@ public class Classpath implements Iterable<String>
return unmodifiableElements;
}
+ /**
+ * @deprecated this should be package private method which returns List of Files. It will be
+ * removed in the next major version.
+ */
+ @Deprecated
public List<URL> getAsUrlList()
throws MalformedURLException
{
@@ -128,7 +134,8 @@ public class Classpath implements Iterable<String>
StringBuilder sb = new StringBuilder();
for ( String element : unmodifiableElements )
{
- sb.append( element ).append( File.pathSeparatorChar );
+ sb.append( element )
+ .append( pathSeparatorChar );
}
System.setProperty( propertyName, sb.toString() );
}
@@ -155,9 +162,8 @@ public class Classpath implements Iterable<String>
{
try
{
- List<URL> urls = getAsUrlList();
IsolatedClassLoader classLoader = new IsolatedClassLoader( parent, childDelegation, roleName );
- for ( URL url : urls )
+ for ( URL url : getAsUrlList() )
{
classLoader.addURL( url );
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java
index 712624c..31db087 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java
@@ -49,9 +49,15 @@ public class IsolatedClassLoader
this.roleName = roleName;
}
+ /**
+ * @deprecated this method will use {@link java.io.File} instead of {@link URL} in the next
+ * major version.
+ */
+ @Deprecated
public void addURL( URL url )
{
// avoid duplicates
+ // todo avoid URL due to calling equals method may cause some overhead due to resolving host or file.
if ( !urls.contains( url ) )
{
super.addURL( url );
@@ -62,13 +68,9 @@ public class IsolatedClassLoader
public synchronized Class loadClass( String name )
throws ClassNotFoundException
{
- Class c;
-
if ( childDelegation )
{
- c = findLoadedClass( name );
-
- ClassNotFoundException ex = null;
+ Class<?> c = findLoadedClass( name );
if ( c == null )
{
@@ -78,26 +80,23 @@ public class IsolatedClassLoader
}
catch ( ClassNotFoundException e )
{
- ex = e;
-
- if ( parent != null )
+ if ( parent == null )
+ {
+ throw e;
+ }
+ else
{
c = parent.loadClass( name );
}
}
}
- if ( c == null )
- {
- throw ex;
- }
+ return c;
}
else
{
- c = super.loadClass( name );
+ return super.loadClass( name );
}
-
- return c;
}
public String toString()
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
index c4a7103..5a19e26 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
@@ -119,7 +119,6 @@ public class PropertiesWrapper
}
}
-
Classpath getClasspath( String prefix )
{
List<String> elements = getStringList( prefix );
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TypeEncodedValue.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TypeEncodedValue.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TypeEncodedValue.java
index 59c8cd2..bbd0f70 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TypeEncodedValue.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/TypeEncodedValue.java
@@ -22,16 +22,16 @@ package org.apache.maven.surefire.booter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.Properties;
-import org.apache.maven.surefire.util.ReflectionUtils;
+
+import static org.apache.maven.surefire.util.ReflectionUtils.loadClass;
/**
* @author Kristian Rosenvold
*/
public class TypeEncodedValue
{
- String type;
-
- String value;
+ private final String type;
+ private final String value;
public TypeEncodedValue( String type, String value )
{
@@ -51,6 +51,7 @@ public class TypeEncodedValue
public Object getDecodedValue( ClassLoader classLoader )
{
+ // todo: use jdk6 switch case
if ( type.trim().length() == 0 )
{
return null;
@@ -61,7 +62,7 @@ public class TypeEncodedValue
}
else if ( isTypeClass() )
{
- return ReflectionUtils.loadClass( classLoader, value );
+ return loadClass( classLoader, value );
}
else if ( type.equals( File.class.getName() ) )
{
@@ -77,17 +78,17 @@ public class TypeEncodedValue
}
else if ( type.equals( Properties.class.getName() ) )
{
- final Properties result = new Properties();
+ Properties result = new Properties();
+ // todo: use jdk7 Closable
try
{
- ByteArrayInputStream bais = new ByteArrayInputStream( value.getBytes( "8859_1" ) );
- result.load( bais );
+ result.load( new ByteArrayInputStream( value.getBytes( "8859_1" ) ) );
+ return result;
}
catch ( Exception e )
{
- throw new RuntimeException( "bug in property conversion", e );
+ throw new IllegalStateException( "bug in property conversion", e );
}
- return result;
}
else
{
@@ -95,7 +96,6 @@ public class TypeEncodedValue
}
}
- @SuppressWarnings( "SimplifiableIfStatement" )
public boolean equals( Object o )
{
if ( this == o )
@@ -109,11 +109,7 @@ public class TypeEncodedValue
TypeEncodedValue that = (TypeEncodedValue) o;
- if ( type != null ? !type.equals( that.type ) : that.type != null )
- {
- return false;
- }
- return !( value != null ? !value.equals( that.value ) : that.value != null );
+ return equalsType( that ) && equalsValue( that );
}
@@ -123,4 +119,14 @@ public class TypeEncodedValue
result = 31 * result + ( value != null ? value.hashCode() : 0 );
return result;
}
+
+ private boolean equalsType( TypeEncodedValue that )
+ {
+ return type == null ? that.type == null : type.equals( that.type );
+ }
+
+ private boolean equalsValue( TypeEncodedValue that )
+ {
+ return value == null ? that.value == null : value.equals( that.value );
+ }
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java
index 6eeae93..c91bb12 100644
--- a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java
+++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java
@@ -27,14 +27,15 @@ import org.junit.runner.Description;
import org.junit.runner.manipulation.Filter;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import static java.util.Collections.addAll;
+import static org.junit.runner.Description.createSuiteDescription;
+
final class GroupMatcherCategoryFilter
extends Filter
{
-
private final AndGroupMatcher matcher;
GroupMatcherCategoryFilter( GroupMatcher included, GroupMatcher excluded )
@@ -68,8 +69,8 @@ final class GroupMatcherCategoryFilter
}
else
{
- return shouldRun( description, Description.createSuiteDescription( description.getTestClass() ),
- description.getTestClass() );
+ Class<?> testClass = description.getTestClass();
+ return shouldRun( description, createSuiteDescription( testClass ), testClass );
}
}
@@ -80,7 +81,7 @@ final class GroupMatcherCategoryFilter
Category cat = clazz.getSuperclass().getAnnotation( Category.class );
if ( cat != null )
{
- Collections.addAll( cats, cat.value() );
+ addAll( cats, cat.value() );
}
else
{
@@ -101,7 +102,7 @@ final class GroupMatcherCategoryFilter
Category cat = description.getAnnotation( Category.class );
if ( cat != null )
{
- Collections.addAll( cats, cat.value() );
+ addAll( cats, cat.value() );
}
if ( parent != null )
@@ -109,7 +110,7 @@ final class GroupMatcherCategoryFilter
cat = parent.getAnnotation( Category.class );
if ( cat != null )
{
- Collections.addAll( cats, cat.value() );
+ addAll( cats, cat.value() );
}
}
@@ -124,7 +125,7 @@ final class GroupMatcherCategoryFilter
cat = testClass.getAnnotation( Category.class );
if ( cat != null )
{
- Collections.addAll( cats, cat.value() );
+ addAll( cats, cat.value() );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java
index 505df6e..0eca387 100644
--- a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java
+++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java
@@ -59,7 +59,7 @@ final class RequestedTest
public String describe()
{
String description = test.toString();
- return description == null || description.length() == 0 ? "*" : description;
+ return description.length() == 0 ? "*" : description;
}
@Override
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java b/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java
index 362d615..d0f15cb 100644
--- a/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java
+++ b/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/PojoTestSet.java
@@ -37,27 +37,26 @@ import org.apache.maven.surefire.testset.TestSetFailedException;
public class PojoTestSet
implements SurefireTestSet
{
-
private static final String TEST_METHOD_PREFIX = "test";
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
private final Object testObject;
+ private final Class<?> testClass;
+
private List<Method> testMethods;
private Method setUpMethod;
private Method tearDownMethod;
- private final Class testClass;
-
- public PojoTestSet( Class testClass )
+ public PojoTestSet( Class<?> testClass )
throws TestSetFailedException
{
if ( testClass == null )
{
- throw new NullPointerException( "testClass is null" );
+ throw new IllegalArgumentException( "testClass is null" );
}
this.testClass = testClass;
@@ -295,7 +294,7 @@ public class PojoTestSet
return testClass.getName();
}
- public Class getTestClass()
+ public Class<?> getTestClass()
{
return testClass;
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
index f39fddb..d407baa 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
@@ -50,6 +50,8 @@ import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
import static org.apache.maven.surefire.junitcore.pc.ParallelComputerUtil.resolveConcurrency;
+import static org.apache.maven.surefire.junitcore.pc.SchedulingStrategies.createParallelStrategy;
+import static org.apache.maven.surefire.junitcore.pc.SchedulingStrategies.createParallelStrategyUnbounded;
import static org.apache.maven.surefire.junitcore.pc.Type.CLASSES;
import static org.apache.maven.surefire.junitcore.pc.Type.METHODS;
import static org.apache.maven.surefire.junitcore.pc.Type.SUITES;
@@ -210,7 +212,7 @@ public final class ParallelComputerBuilder
if ( parallelType == null )
{
- throw new NullPointerException( "null parallelType" );
+ throw new IllegalArgumentException( "null parallelType" );
}
parallelGroups.put( parallelType, nThreads );
@@ -252,19 +254,19 @@ public final class ParallelComputerBuilder
private final SingleThreadScheduler notThreadSafeTests =
new SingleThreadScheduler( ParallelComputerBuilder.this.logger );
- final Collection<ParentRunner> suites = new LinkedHashSet<ParentRunner>();
+ private final Collection<ParentRunner> suites = new LinkedHashSet<ParentRunner>();
- final Collection<ParentRunner> nestedSuites = new LinkedHashSet<ParentRunner>();
+ private final Collection<ParentRunner> nestedSuites = new LinkedHashSet<ParentRunner>();
- final Collection<ParentRunner> classes = new LinkedHashSet<ParentRunner>();
+ private final Collection<ParentRunner> classes = new LinkedHashSet<ParentRunner>();
- final Collection<ParentRunner> nestedClasses = new LinkedHashSet<ParentRunner>();
+ private final Collection<ParentRunner> nestedClasses = new LinkedHashSet<ParentRunner>();
- final Collection<Runner> notParallelRunners = new LinkedHashSet<Runner>();
+ private final Collection<Runner> notParallelRunners = new LinkedHashSet<Runner>();
- int poolCapacity;
+ private int poolCapacity;
- boolean splitPool;
+ private boolean splitPool;
private final Map<Type, Integer> allGroups;
@@ -280,6 +282,41 @@ public final class ParallelComputerBuilder
splitPool = ParallelComputerBuilder.this.useSeparatePools;
}
+ Collection<ParentRunner> getSuites()
+ {
+ return suites;
+ }
+
+ Collection<ParentRunner> getNestedSuites()
+ {
+ return nestedSuites;
+ }
+
+ Collection<ParentRunner> getClasses()
+ {
+ return classes;
+ }
+
+ Collection<ParentRunner> getNestedClasses()
+ {
+ return nestedClasses;
+ }
+
+ Collection<Runner> getNotParallelRunners()
+ {
+ return notParallelRunners;
+ }
+
+ int getPoolCapacity()
+ {
+ return poolCapacity;
+ }
+
+ boolean isSplitPool()
+ {
+ return splitPool;
+ }
+
@Override
protected ShutdownResult describeStopped( boolean shutdownNow )
{
@@ -365,10 +402,13 @@ public final class ParallelComputerBuilder
private void determineThreadCounts( long suites, long classes, long methods )
throws TestSetFailedException
{
- final JUnitCoreParameters parameters = ParallelComputerBuilder.this.parameters;
- final boolean optimize = ParallelComputerBuilder.this.optimize;
- RunnerCounter counts = new RunnerCounter( suites, classes, methods );
- Concurrency concurrency = resolveConcurrency( parameters, optimize ? counts : null );
+ RunnerCounter counts = null;
+ if ( ParallelComputerBuilder.this.optimize )
+ {
+ counts = new RunnerCounter( suites, classes, methods );
+ }
+ Concurrency concurrency =
+ resolveConcurrency( ParallelComputerBuilder.this.parameters, counts );
allGroups.put( SUITES, concurrency.suites );
allGroups.put( CLASSES, concurrency.classes );
allGroups.put( METHODS, concurrency.methods );
@@ -413,7 +453,9 @@ public final class ParallelComputerBuilder
private Scheduler createMaster( ExecutorService pool, int poolSize )
{
- final int finalRunnersCounter = countFinalRunners(); // can be 0, 1, 2 or 3
+ // can be 0, 1, 2 or 3
+ final int finalRunnersCounter = countFinalRunners();
+
final SchedulingStrategy strategy;
if ( finalRunnersCounter <= 1 || poolSize <= 1 )
{
@@ -425,8 +467,7 @@ public final class ParallelComputerBuilder
}
else
{
- strategy = SchedulingStrategies.createParallelStrategy( ParallelComputerBuilder.this.logger,
- finalRunnersCounter );
+ strategy = createParallelStrategy( ParallelComputerBuilder.this.logger, finalRunnersCounter );
}
return new Scheduler( ParallelComputerBuilder.this.logger, null, strategy );
}
@@ -596,8 +637,8 @@ public final class ParallelComputerBuilder
private Scheduler createScheduler( Description desc, ExecutorService pool, boolean doParallel,
Balancer concurrency )
{
- doParallel &= pool != null;
- SchedulingStrategy strategy = doParallel
+ SchedulingStrategy strategy =
+ doParallel & pool != null
? new SharedThreadPoolStrategy( ParallelComputerBuilder.this.logger, pool )
: new InvokerStrategy( ParallelComputerBuilder.this.logger );
return new Scheduler( ParallelComputerBuilder.this.logger, desc, master, strategy, concurrency );
@@ -608,7 +649,7 @@ public final class ParallelComputerBuilder
final SchedulingStrategy strategy;
if ( poolSize == Integer.MAX_VALUE )
{
- strategy = SchedulingStrategies.createParallelStrategyUnbounded( ParallelComputerBuilder.this.logger );
+ strategy = createParallelStrategyUnbounded( ParallelComputerBuilder.this.logger );
}
else if ( poolSize == 0 )
{
@@ -616,7 +657,7 @@ public final class ParallelComputerBuilder
}
else
{
- strategy = SchedulingStrategies.createParallelStrategy( ParallelComputerBuilder.this.logger, poolSize );
+ strategy = createParallelStrategy( ParallelComputerBuilder.this.logger, poolSize );
}
return new Scheduler( ParallelComputerBuilder.this.logger, null, master, strategy );
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
index 50faaa9..aca5d68 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
@@ -122,12 +122,12 @@ public class ParallelComputerBuilderTest
Result result = new JUnitCore().run( computer, TestSuite.class );
long timeSpent = stopwatch.runtime( MILLISECONDS );
- assertThat( computer.suites.size(), is( 1 ) );
- assertThat( computer.classes.size(), is( 0 ) );
- assertThat( computer.nestedClasses.size(), is( 2 ) );
- assertThat( computer.nestedSuites.size(), is( 0 ) );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 4 ) );
+ assertThat( computer.getSuites().size(), is( 1 ) );
+ assertThat( computer.getClasses().size(), is( 0 ) );
+ assertThat( computer.getNestedClasses().size(), is( 2 ) );
+ assertThat( computer.getNestedSuites().size(), is( 0 ) );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 4 ) );
assertTrue( result.wasSuccessful() );
if ( Class1.maxConcurrentMethods == 1 )
{
@@ -157,12 +157,12 @@ public class ParallelComputerBuilderTest
Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
long timeSpent = stopwatch.runtime( MILLISECONDS );
- assertThat( computer.suites.size(), is( 1 ) );
- assertThat( computer.classes.size(), is( 1 ) );
- assertThat( computer.nestedClasses.size(), is( 2 ) );
- assertThat( computer.nestedSuites.size(), is( 0 ) );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 5 ) );
+ assertThat( computer.getSuites().size(), is( 1 ) );
+ assertThat( computer.getClasses().size(), is( 1 ) );
+ assertThat( computer.getNestedClasses().size(), is( 2 ) );
+ assertThat( computer.getNestedSuites().size(), is( 0 ) );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 5 ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 2 ) );
assertThat( timeSpent, anyOf( between( 1450, 1750 ), between( 1950, 2250 ), between( 2450, 2750 ) ) );
@@ -183,12 +183,12 @@ public class ParallelComputerBuilderTest
Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
long timeSpent = stopwatch.runtime( MILLISECONDS );
- assertThat( computer.suites.size(), is( 1 ) );
- assertThat( computer.classes.size(), is( 1 ) );
- assertThat( computer.nestedClasses.size(), is( 2 ) );
- assertThat( computer.nestedSuites.size(), is( 0 ) );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 8 ) );
+ assertThat( computer.getSuites().size(), is( 1 ) );
+ assertThat( computer.getClasses().size(), is( 1 ) );
+ assertThat( computer.getNestedClasses().size(), is( 2 ) );
+ assertThat( computer.getNestedSuites().size(), is( 0 ) );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 8 ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 4 ) );
assertThat( timeSpent, between( 950, 1250 ) );
@@ -215,12 +215,12 @@ public class ParallelComputerBuilderTest
Result result = new JUnitCore().run( computer, TestSuite.class );
long timeSpent = stopwatch.runtime( MILLISECONDS );
- assertThat( computer.suites.size(), is( 1 ) );
- assertThat( computer.classes.size(), is( 0 ) );
- assertThat( computer.nestedClasses.size(), is( 2 ) );
- assertThat( computer.nestedSuites.size(), is( 0 ) );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 3 ) );
+ assertThat( computer.getSuites().size(), is( 1 ) );
+ assertThat( computer.getClasses().size(), is( 0 ) );
+ assertThat( computer.getNestedClasses().size(), is( 2 ) );
+ assertThat( computer.getNestedSuites().size(), is( 0 ) );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 3 ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 1 ) );
assertThat( timeSpent, between( 1950, 2250 ) );
@@ -239,12 +239,12 @@ public class ParallelComputerBuilderTest
Result result = new JUnitCore().run( computer, TestSuite.class );
long timeSpent = stopwatch.runtime( MILLISECONDS );
- assertThat( computer.suites.size(), is( 1 ) );
- assertThat( computer.classes.size(), is( 0 ) );
- assertThat( computer.nestedClasses.size(), is( 2 ) );
- assertThat( computer.nestedSuites.size(), is( 0 ) );
- assertTrue( computer.splitPool );
- assertThat( computer.poolCapacity, is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
+ assertThat( computer.getSuites().size(), is( 1 ) );
+ assertThat( computer.getClasses().size(), is( 0 ) );
+ assertThat( computer.getNestedClasses().size(), is( 2 ) );
+ assertThat( computer.getNestedSuites().size(), is( 0 ) );
+ assertTrue( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 3 ) );
assertThat( timeSpent, between( 950, 1250 ) );
@@ -266,12 +266,12 @@ public class ParallelComputerBuilderTest
Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
long timeSpent = stopwatch.runtime( MILLISECONDS );
- assertThat( computer.suites.size(), is( 1 ) );
- assertThat( computer.classes.size(), is( 1 ) );
- assertThat( computer.nestedClasses.size(), is( 2 ) );
- assertThat( computer.nestedSuites.size(), is( 0 ) );
- assertTrue( computer.splitPool );
- assertThat( computer.poolCapacity, is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
+ assertThat( computer.getSuites().size(), is( 1 ) );
+ assertThat( computer.getClasses().size(), is( 1 ) );
+ assertThat( computer.getNestedClasses().size(), is( 2 ) );
+ assertThat( computer.getNestedSuites().size(), is( 0 ) );
+ assertTrue( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 3 ) );
assertThat( timeSpent, between( 950, 1250 ) );
@@ -290,12 +290,12 @@ public class ParallelComputerBuilderTest
Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
long timeSpent = stopwatch.runtime( MILLISECONDS );
- assertThat( computer.suites.size(), is( 1 ) );
- assertThat( computer.classes.size(), is( 1 ) );
- assertThat( computer.nestedClasses.size(), is( 2 ) );
- assertThat( computer.nestedSuites.size(), is( 0 ) );
- assertTrue( computer.splitPool );
- assertThat( computer.poolCapacity, is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
+ assertThat( computer.getSuites().size(), is( 1 ) );
+ assertThat( computer.getClasses().size(), is( 1 ) );
+ assertThat( computer.getNestedClasses().size(), is( 2 ) );
+ assertThat( computer.getNestedSuites().size(), is( 0 ) );
+ assertTrue( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 2 ) );
assertThat( timeSpent, between( 1450, 1750 ) );
@@ -420,13 +420,13 @@ public class ParallelComputerBuilderTest
assertNotNull( NotThreadSafeTest1.t );
assertNotNull( NotThreadSafeTest2.t );
assertSame( NotThreadSafeTest1.t, NotThreadSafeTest2.t );
- assertThat( computer.notParallelRunners.size(), is( 2 ) );
- assertTrue( computer.suites.isEmpty() );
- assertTrue( computer.classes.isEmpty() );
- assertTrue( computer.nestedClasses.isEmpty() );
- assertTrue( computer.nestedSuites.isEmpty() );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 6 ) );
+ assertThat( computer.getNotParallelRunners().size(), is( 2 ) );
+ assertTrue( computer.getSuites().isEmpty() );
+ assertTrue( computer.getClasses().isEmpty() );
+ assertTrue( computer.getNestedClasses().isEmpty() );
+ assertTrue( computer.getNestedSuites().isEmpty() );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 6 ) );
}
@Test
@@ -442,13 +442,13 @@ public class ParallelComputerBuilderTest
assertNotNull( NormalTest1.t );
assertThat( NormalTest1.t.getName(), is( not( "maven-surefire-plugin@NotThreadSafe" ) ) );
assertNotSame( NotThreadSafeTest1.t, NormalTest1.t );
- assertThat( computer.notParallelRunners.size(), is( 1 ) );
- assertTrue( computer.suites.isEmpty() );
- assertThat( computer.classes.size(), is( 1 ) );
- assertTrue( computer.nestedClasses.isEmpty() );
- assertTrue( computer.nestedSuites.isEmpty() );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 6 ) );
+ assertThat( computer.getNotParallelRunners().size(), is( 1 ) );
+ assertTrue( computer.getSuites().isEmpty() );
+ assertThat( computer.getClasses().size(), is( 1 ) );
+ assertTrue( computer.getNestedClasses().isEmpty() );
+ assertTrue( computer.getNestedSuites().isEmpty() );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 6 ) );
}
@Test
@@ -465,13 +465,13 @@ public class ParallelComputerBuilderTest
assertSame( NormalTest1.t, NormalTest2.t );
assertThat( NormalTest1.t.getName(), is( "maven-surefire-plugin@NotThreadSafe" ) );
assertThat( NormalTest2.t.getName(), is( "maven-surefire-plugin@NotThreadSafe" ) );
- assertThat( computer.notParallelRunners.size(), is( 1 ) );
- assertTrue( computer.suites.isEmpty() );
- assertTrue( computer.classes.isEmpty() );
- assertTrue( computer.nestedClasses.isEmpty() );
- assertTrue( computer.nestedSuites.isEmpty() );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 5 ) );
+ assertThat( computer.getNotParallelRunners().size(), is( 1 ) );
+ assertTrue( computer.getSuites().isEmpty() );
+ assertTrue( computer.getClasses().isEmpty() );
+ assertTrue( computer.getNestedClasses().isEmpty() );
+ assertTrue( computer.getNestedSuites().isEmpty() );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 5 ) );
}
@Test
@@ -487,13 +487,13 @@ public class ParallelComputerBuilderTest
assertNotNull( NormalTest1.t );
assertThat( NormalTest1.t.getName(), is( not( "maven-surefire-plugin@NotThreadSafe" ) ) );
assertNotSame( NotThreadSafeTest1.t, NormalTest1.t );
- assertTrue( computer.notParallelRunners.isEmpty() );
- assertThat( computer.suites.size(), is( 1 ) );
- assertTrue( computer.classes.isEmpty() );
- assertThat( computer.nestedClasses.size(), is( 1 ) );
- assertTrue( computer.nestedSuites.isEmpty() );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 10 ) );
+ assertTrue( computer.getNotParallelRunners().isEmpty() );
+ assertThat( computer.getSuites().size(), is( 1 ) );
+ assertTrue( computer.getClasses().isEmpty() );
+ assertThat( computer.getNestedClasses().size(), is( 1 ) );
+ assertTrue( computer.getNestedSuites().isEmpty() );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 10 ) );
}
@Test
@@ -509,13 +509,13 @@ public class ParallelComputerBuilderTest
assertNotNull( NormalTest1.t );
assertThat( NormalTest1.t.getName(), is( "maven-surefire-plugin@NotThreadSafe" ) );
assertSame( NotThreadSafeTest3.t, NormalTest1.t );
- assertThat( computer.notParallelRunners.size(), is( 1 ) );
- assertTrue( computer.suites.isEmpty() );
- assertTrue( computer.classes.isEmpty() );
- assertTrue( computer.nestedClasses.isEmpty() );
- assertTrue( computer.nestedSuites.isEmpty() );
- assertFalse( computer.splitPool );
- assertThat( computer.poolCapacity, is( 10 ) );
+ assertThat( computer.getNotParallelRunners().size(), is( 1 ) );
+ assertTrue( computer.getSuites().isEmpty() );
+ assertTrue( computer.getClasses().isEmpty() );
+ assertTrue( computer.getNestedClasses().isEmpty() );
+ assertTrue( computer.getNestedSuites().isEmpty() );
+ assertFalse( computer.isSplitPool() );
+ assertThat( computer.getPoolCapacity(), is( 10 ) );
}
@Test
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
index 96e0b85..91ade69 100755
--- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
+++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
@@ -24,11 +24,15 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
-import org.apache.maven.surefire.booter.ProviderParameterNames;
import org.apache.maven.surefire.testset.TestSetFailedException;
import org.testng.TestNG;
import org.testng.xml.XmlSuite;
+import static java.lang.Integer.parseInt;
+import static org.apache.maven.surefire.booter.ProviderParameterNames.PARALLEL_PROP;
+import static org.apache.maven.surefire.booter.ProviderParameterNames.THREADCOUNT_PROP;
+import static org.apache.maven.surefire.testng.conf.AbstractDirectConfigurator.loadListenerClasses;
+
/**
* TestNG configurator for 5.3+ versions. TestNG exposes a {@link org.testng.TestNG#configure(java.util.Map)} method.
* All suppported TestNG options are passed in String format, except
@@ -55,11 +59,11 @@ public class TestNGMapConfigurator
public void configure( XmlSuite suite, Map<String, String> options )
throws TestSetFailedException
{
- String threadCountString = options.get( ProviderParameterNames.THREADCOUNT_PROP );
- int threadCount = ( null != threadCountString ) ? Integer.parseInt( threadCountString ) : 1;
+ String threadCountAsString = options.get( THREADCOUNT_PROP );
+ int threadCount = threadCountAsString == null ? 1 : parseInt( threadCountAsString );
suite.setThreadCount( threadCount );
- String parallel = options.get( ProviderParameterNames.PARALLEL_PROP );
+ String parallel = options.get( PARALLEL_PROP );
if ( parallel != null )
{
suite.setParallel( parallel );
@@ -75,6 +79,7 @@ public class TestNGMapConfigurator
{
String key = entry.getKey();
Object val = entry.getValue();
+ // todo: use switch-case of jdk7
if ( "listener".equals( key ) )
{
val = convertListeners( entry.getValue() );
@@ -114,7 +119,7 @@ public class TestNGMapConfigurator
{
val = convert( val, Boolean.class );
}
- else if ( ProviderParameterNames.THREADCOUNT_PROP.equals( key ) )
+ else if ( THREADCOUNT_PROP.equals( key ) )
{
val = convert ( val, String.class );
}
@@ -144,10 +149,9 @@ public class TestNGMapConfigurator
// ReporterConfig only became available in later versions of TestNG
protected Object convertReporterConfig( Object val )
{
- final String reporterConfigClassName = "org.testng.ReporterConfig";
try
{
- Class<?> reporterConfig = Class.forName( reporterConfigClassName );
+ Class<?> reporterConfig = Class.forName( "org.testng.ReporterConfig" );
Method deserialize = reporterConfig.getMethod( "deserialize", String.class );
Object rc = deserialize.invoke( null, val );
ArrayList<Object> reportersList = new ArrayList<Object>();
@@ -162,7 +166,7 @@ public class TestNGMapConfigurator
protected Object convertListeners( String listenerClasses ) throws TestSetFailedException
{
- return AbstractDirectConfigurator.loadListenerClasses( listenerClasses );
+ return loadListenerClasses( listenerClasses );
}
protected Object convert( Object val, Class<?> type )
@@ -171,26 +175,25 @@ public class TestNGMapConfigurator
{
return null;
}
- if ( type.isAssignableFrom( val.getClass() ) )
+ else if ( type.isAssignableFrom( val.getClass() ) )
{
return val;
}
-
- if ( ( type == Boolean.class || type == boolean.class ) && val.getClass() == String.class )
+ else if ( ( type == Boolean.class || type == boolean.class ) && val.getClass() == String.class )
{
return Boolean.valueOf( (String) val );
}
-
- if ( ( type == Integer.class || type == int.class ) && val.getClass() == String.class )
+ else if ( ( type == Integer.class || type == int.class ) && val.getClass() == String.class )
{
return Integer.valueOf( (String) val );
}
-
- if ( type == String.class )
+ else if ( type == String.class )
{
return val.toString();
}
-
- return val;
+ else
+ {
+ return val;
+ }
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/eaf25fa0/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
----------------------------------------------------------------------
diff --git a/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
index be35b75..f027b29 100644
--- a/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
+++ b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
@@ -115,6 +115,7 @@ public final class TestSuiteXmlParser
{
try
{
+ // todo: use jdk7 switch-case
if ( "testsuite".equals( qName ) )
{
defaultSuite = new ReportTestSuite();
@@ -217,6 +218,7 @@ public final class TestSuiteXmlParser
public void endElement( String uri, String localName, String qName )
throws SAXException
{
+ // todo: use jdk7 switch-case
if ( "testcase".equals( qName ) )
{
currentSuite.getTestCases().add( testCase );