[SUREFIRE] refactoring: varargs and Class wildcard <?>
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/b586cef9 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/b586cef9 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/b586cef9 Branch: refs/heads/master Commit: b586cef94f7bb73185d280fcf9c7731c15459a61 Parents: 01c32aa Author: Tibor17 <tibo...@lycos.com> Authored: Sat Oct 10 13:56:24 2015 +0200 Committer: Tibor17 <tibo...@lycos.com> Committed: Sat Oct 10 13:56:24 2015 +0200 ---------------------------------------------------------------------- .../maven/plugin/surefire/CommonReflector.java | 12 +- .../surefire/booter/MasterProcessReader.java | 14 +-- .../surefire/booter/SurefireReflector.java | 121 ++++++++++--------- .../maven/surefire/util/ReflectionUtils.java | 41 +++---- .../maven/surefire/booter/ProviderFactory.java | 25 ++-- .../surefire/common/junit3/JUnit3Reflector.java | 38 +++--- .../common/junit3/JUnit3TestChecker.java | 4 +- .../surefire/common/junit4/JUnit4Reflector.java | 5 +- .../common/junit4/JUnit4TestChecker.java | 6 +- .../common/junit48/JUnit48Reflector.java | 4 +- .../maven/surefire/junit/JUnit3Provider.java | 16 +-- .../maven/surefire/junit/JUnitTestSet.java | 6 +- .../maven/surefire/junit4/JUnit4Provider.java | 2 +- 13 files changed, 147 insertions(+), 147 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java index ec48e42..a8be45b 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java @@ -62,13 +62,13 @@ public class CommonReflector Object createStartupReportConfiguration( @Nonnull StartupReportConfiguration reporterConfiguration ) { - Constructor<?> constructor = ReflectionUtils.getConstructor( this.startupReportConfiguration, - new Class[]{ boolean.class, boolean.class, - String.class, boolean.class, boolean.class, - File.class, boolean.class, String.class, - String.class, boolean.class, int.class } ); + Constructor<?> constructor = ReflectionUtils.getConstructor( startupReportConfiguration, + boolean.class, boolean.class, + String.class, boolean.class, boolean.class, + File.class, boolean.class, String.class, + String.class, boolean.class, int.class ); //noinspection BooleanConstructorCall - final Object[] params = { reporterConfiguration.isUseFile(), reporterConfiguration.isPrintSummary(), + Object[] params = { reporterConfiguration.isUseFile(), reporterConfiguration.isPrintSummary(), reporterConfiguration.getReportFormat(), reporterConfiguration.isRedirectTestOutputToFile(), reporterConfiguration.isDisableXmlReport(), reporterConfiguration.getReportsDirectory(), reporterConfiguration.isTrimStackTrace(), reporterConfiguration.getReportNameSuffix(), http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java index dcb7d2a..6bd12ad 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java @@ -236,7 +236,7 @@ public final class MasterProcessReader /** * thread-safety: Must be called from single thread like here the reader thread only. */ - private void insertForQueue( Command cmd ) + private void insertToQueue( Command cmd ) { MasterProcessCommand expectedCommandType = cmd.getCommandType(); switch ( expectedCommandType ) @@ -253,7 +253,7 @@ public final class MasterProcessReader } } - private void insertForListeners( Command cmd ) + private void insertToListeners( Command cmd ) { MasterProcessCommand expectedCommandType = cmd.getCommandType(); for ( TwoPropertiesWrapper<MasterProcessCommand, MasterProcessListener> listenerWrapper @@ -273,8 +273,8 @@ public final class MasterProcessReader */ private void insert( Command cmd ) { - insertForQueue( cmd ); - insertForListeners( cmd ); + insertToQueue( cmd ); + insertToListeners( cmd ); } private final class ClassesIterable @@ -421,7 +421,7 @@ public final class MasterProcessReader Command command = decode( stdIn ); if ( command != null ) { - insertForQueue( command ); + insertToQueue( command ); } return command; } @@ -478,7 +478,7 @@ public final class MasterProcessReader wakeupWaiters(); break; case SHUTDOWN: - insertForQueue( Command.TEST_SET_FINISHED ); + insertToQueue( Command.TEST_SET_FINISHED ); wakeupWaiters(); break; default: @@ -486,7 +486,7 @@ public final class MasterProcessReader break; } - insertForListeners( command ); + insertToListeners( command ); } } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java index 96bc3c0..bd73908 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java @@ -39,12 +39,20 @@ import org.apache.maven.surefire.testset.RunOrderParameters; import org.apache.maven.surefire.testset.TestArtifactInfo; import org.apache.maven.surefire.testset.TestListResolver; import org.apache.maven.surefire.testset.TestRequest; -import org.apache.maven.surefire.util.ReflectionUtils; import org.apache.maven.surefire.util.RunOrder; import org.apache.maven.surefire.util.SurefireReflectionException; import static java.util.Collections.checkedList; +import static org.apache.maven.surefire.util.ReflectionUtils.getConstructor; +import static org.apache.maven.surefire.util.ReflectionUtils.getMethod; +import static org.apache.maven.surefire.util.ReflectionUtils.invokeGetter; +import static org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray; +import static org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg; +import static org.apache.maven.surefire.util.ReflectionUtils.invokeSetter; +import static org.apache.maven.surefire.util.ReflectionUtils.instantiateTwoArgs; +import static org.apache.maven.surefire.util.ReflectionUtils.newInstance; + /** * Does reflection based invocation of the surefire methods. * <p/> @@ -134,15 +142,14 @@ public class SurefireReflector { return result; } - final Integer getCompletedCount1 = (Integer) ReflectionUtils.invokeGetter( result, "getCompletedCount" ); - final Integer getErrors = (Integer) ReflectionUtils.invokeGetter( result, "getErrors" ); - final Integer getSkipped = (Integer) ReflectionUtils.invokeGetter( result, "getSkipped" ); - final Integer getFailures = (Integer) ReflectionUtils.invokeGetter( result, "getFailures" ); + int getCompletedCount1 = (Integer) invokeGetter( result, "getCompletedCount" ); + int getErrors = (Integer) invokeGetter( result, "getErrors" ); + int getSkipped = (Integer) invokeGetter( result, "getSkipped" ); + int getFailures = (Integer) invokeGetter( result, "getFailures" ); return new RunResult( getCompletedCount1, getErrors, getFailures, getSkipped ); } - /** * @noinspection UnusedDeclaration */ @@ -168,7 +175,6 @@ public class SurefireReflector } } - Object createTestRequest( TestRequest suiteDefinition ) { if ( suiteDefinition == null ) @@ -178,10 +184,13 @@ public class SurefireReflector else { Object resolver = createTestListResolver( suiteDefinition.getTestListResolver() ); - Class[] arguments = { List.class, File.class, testListResolver, int.class }; - Constructor constructor = ReflectionUtils.getConstructor( testRequest, arguments ); - return ReflectionUtils.newInstance( constructor, new Object[]{ suiteDefinition.getSuiteXmlFiles(), - suiteDefinition.getTestSourceDirectory(), resolver, suiteDefinition.getRerunFailingTestsCount() } ); + Class<?>[] arguments = { List.class, File.class, testListResolver, int.class }; + Constructor constructor = getConstructor( testRequest, arguments ); + return newInstance( constructor, + suiteDefinition.getSuiteXmlFiles(), + suiteDefinition.getTestSourceDirectory(), + resolver, + suiteDefinition.getRerunFailingTestsCount() ); } } @@ -193,8 +202,8 @@ public class SurefireReflector } else { - Constructor constructor = ReflectionUtils.getConstructor( testListResolver, new Class[] { String.class } ); - return ReflectionUtils.newInstance( constructor, new Object[] { resolver.getPluginParameterTest() } ); + Constructor constructor = getConstructor( testListResolver, String.class ); + return newInstance( constructor, resolver.getPluginParameterTest() ); } } @@ -205,15 +214,15 @@ public class SurefireReflector return null; } //Can't use the constructor with the RunOrder parameter. Using it causes some integration tests to fail. - Class[] arguments = { File.class, List.class, List.class, List.class, boolean.class, String.class }; - Constructor constructor = ReflectionUtils.getConstructor( this.directoryScannerParameters, arguments ); - return ReflectionUtils.newInstance( constructor, - new Object[]{ directoryScannerParameters.getTestClassesDirectory(), - directoryScannerParameters.getIncludes(), - directoryScannerParameters.getExcludes(), - directoryScannerParameters.getSpecificTests(), - directoryScannerParameters.isFailIfNoTests(), - RunOrder.asString( directoryScannerParameters.getRunOrder() ) } ); + Class<?>[] arguments = { File.class, List.class, List.class, List.class, boolean.class, String.class }; + Constructor constructor = getConstructor( this.directoryScannerParameters, arguments ); + return newInstance( constructor, + directoryScannerParameters.getTestClassesDirectory(), + directoryScannerParameters.getIncludes(), + directoryScannerParameters.getExcludes(), + directoryScannerParameters.getSpecificTests(), + directoryScannerParameters.isFailIfNoTests(), + RunOrder.asString( directoryScannerParameters.getRunOrder() ) ); } @@ -224,14 +233,11 @@ public class SurefireReflector return null; } //Can't use the constructor with the RunOrder parameter. Using it causes some integration tests to fail. - Class[] arguments = { String.class, String.class }; - Constructor constructor = ReflectionUtils.getConstructor( this.runOrderParameters, arguments ); - final File runStatisticsFile = runOrderParameters.getRunStatisticsFile(); - return ReflectionUtils.newInstance( constructor, - new Object[]{ RunOrder.asString( runOrderParameters.getRunOrder() ), - runStatisticsFile != null - ? runStatisticsFile.getAbsolutePath() - : null } ); + Class<?>[] arguments = { String.class, String.class }; + Constructor constructor = getConstructor( this.runOrderParameters, arguments ); + File runStatisticsFile = runOrderParameters.getRunStatisticsFile(); + return newInstance( constructor, RunOrder.asString( runOrderParameters.getRunOrder() ), + runStatisticsFile == null ? null : runStatisticsFile.getAbsolutePath() ); } Object createTestArtifactInfo( TestArtifactInfo testArtifactInfo ) @@ -240,19 +246,16 @@ public class SurefireReflector { return null; } - Class[] arguments = { String.class, String.class }; - Constructor constructor = ReflectionUtils.getConstructor( this.testArtifactInfo, arguments ); - return ReflectionUtils.newInstance( constructor, new Object[]{ testArtifactInfo.getVersion(), - testArtifactInfo.getClassifier() } ); + Class<?>[] arguments = { String.class, String.class }; + Constructor constructor = getConstructor( this.testArtifactInfo, arguments ); + return newInstance( constructor, testArtifactInfo.getVersion(), testArtifactInfo.getClassifier() ); } - Object createReporterConfiguration( ReporterConfiguration reporterConfiguration ) + Object createReporterConfiguration( ReporterConfiguration reporterConfig ) { - Constructor constructor = - ReflectionUtils.getConstructor( this.reporterConfiguration, new Class[]{ File.class, boolean.class } ); - return ReflectionUtils.newInstance( constructor, new Object[]{ reporterConfiguration.getReportsDirectory(), - reporterConfiguration.isTrimStackTrace() } ); + Constructor constructor = getConstructor( reporterConfiguration, File.class, boolean.class ); + return newInstance( constructor, reporterConfig.getReportsDirectory(), reporterConfig.isTrimStackTrace() ); } public static ReporterFactory createForkingReporterFactoryInCurrentClassLoader( boolean trimStackTrace, @@ -264,14 +267,13 @@ public class SurefireReflector public Object createBooterConfiguration( ClassLoader surefireClassLoader, Object factoryInstance, boolean insideFork ) { - return ReflectionUtils.instantiateTwoArgs( surefireClassLoader, BaseProviderFactory.class.getName(), - reporterFactory, factoryInstance, boolean.class, insideFork ); + return instantiateTwoArgs( surefireClassLoader, BaseProviderFactory.class.getName(), + reporterFactory, factoryInstance, boolean.class, insideFork ); } public Object instantiateProvider( String providerClassName, Object booterParameters ) { - return ReflectionUtils.instantiateOneArg( surefireClassLoader, providerClassName, this.booterParameters, - booterParameters ); + return instantiateOneArg( surefireClassLoader, providerClassName, this.booterParameters, booterParameters ); } public void setIfDirScannerAware( Object o, DirectoryScannerParameters dirScannerParams ) @@ -295,13 +297,13 @@ public class SurefireReflector newOptions.add( e ); } } - ReflectionUtils.invokeSetter( o, "setMainCliOptions", List.class, newOptions ); + invokeSetter( o, "setMainCliOptions", List.class, newOptions ); } } public void setSkipAfterFailureCount( Object o, int skipAfterFailureCount ) { - ReflectionUtils.invokeSetter( o, "setSkipAfterFailureCount", int.class, skipAfterFailureCount ); + invokeSetter( o, "setSkipAfterFailureCount", int.class, skipAfterFailureCount ); } public void setShutdown( Object o, Shutdown shutdown ) @@ -312,7 +314,7 @@ public class SurefireReflector { if ( shutdown.ordinal() == e.ordinal() ) { - ReflectionUtils.invokeSetter( o, "setShutdown", shutdownClass, e ); + invokeSetter( o, "setShutdown", shutdownClass, e ); break; } } @@ -321,14 +323,14 @@ public class SurefireReflector public void setDirectoryScannerParameters( Object o, DirectoryScannerParameters dirScannerParams ) { - final Object param = createDirectoryScannerParameters( dirScannerParams ); - ReflectionUtils.invokeSetter( o, "setDirectoryScannerParameters", this.directoryScannerParameters, param ); + Object param = createDirectoryScannerParameters( dirScannerParams ); + invokeSetter( o, "setDirectoryScannerParameters", directoryScannerParameters, param ); } public void setRunOrderParameters( Object o, RunOrderParameters runOrderParameters ) { - final Object param = createRunOrderParameters( runOrderParameters ); - ReflectionUtils.invokeSetter( o, "setRunOrderParameters", this.runOrderParameters, param ); + Object param = createRunOrderParameters( runOrderParameters ); + invokeSetter( o, "setRunOrderParameters", this.runOrderParameters, param ); } public void setTestSuiteDefinitionAware( Object o, TestRequest testSuiteDefinition2 ) @@ -341,8 +343,8 @@ public class SurefireReflector void setTestSuiteDefinition( Object o, TestRequest testSuiteDefinition1 ) { - final Object param = createTestRequest( testSuiteDefinition1 ); - ReflectionUtils.invokeSetter( o, "setTestRequest", testRequest, param ); + Object param = createTestRequest( testSuiteDefinition1 ); + invokeSetter( o, "setTestRequest", testRequest, param ); } public void setProviderPropertiesAware( Object o, Map<String, String> properties ) @@ -355,7 +357,7 @@ public class SurefireReflector void setProviderProperties( Object o, Map<String, String> providerProperties ) { - ReflectionUtils.invokeSetter( o, "setProviderProperties", Map.class, providerProperties ); + invokeSetter( o, "setProviderProperties", Map.class, providerProperties ); } public void setReporterConfigurationAware( Object o, ReporterConfiguration reporterConfiguration1 ) @@ -369,8 +371,8 @@ public class SurefireReflector void setReporterConfiguration( Object o, ReporterConfiguration reporterConfiguration ) { - final Object param = createReporterConfiguration( reporterConfiguration ); - ReflectionUtils.invokeSetter( o, "setReporterConfiguration", this.reporterConfiguration, param ); + Object param = createReporterConfiguration( reporterConfiguration ); + invokeSetter( o, "setReporterConfiguration", this.reporterConfiguration, param ); } public void setTestClassLoaderAware( Object o, ClassLoader testClassLoader ) @@ -383,9 +385,8 @@ public class SurefireReflector void setTestClassLoader( Object o, ClassLoader testClassLoader ) { - final Method setter = - ReflectionUtils.getMethod( o, "setClassLoaders", new Class[]{ ClassLoader.class } ); - ReflectionUtils.invokeMethodWithArray( o, setter, new Object[]{ testClassLoader } ); + Method setter = getMethod( o, "setClassLoaders", ClassLoader.class ); + invokeMethodWithArray( o, setter, testClassLoader ); } public void setTestArtifactInfoAware( Object o, TestArtifactInfo testArtifactInfo1 ) @@ -398,8 +399,8 @@ public class SurefireReflector void setTestArtifactInfo( Object o, TestArtifactInfo testArtifactInfo ) { - final Object param = createTestArtifactInfo( testArtifactInfo ); - ReflectionUtils.invokeSetter( o, "setTestArtifactInfo", this.testArtifactInfo, param ); + Object param = createTestArtifactInfo( testArtifactInfo ); + invokeSetter( o, "setTestArtifactInfo", this.testArtifactInfo, param ); } private boolean isRunResult( Object o ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java index 2d633d8..6844dda 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java @@ -37,12 +37,12 @@ public final class ReflectionUtils throw new IllegalStateException( "no instantiable constructor" ); } - public static Method getMethod( Object instance, String methodName, Class[] parameters ) + public static Method getMethod( Object instance, String methodName, Class<?>... parameters ) { return getMethod( instance.getClass(), methodName, parameters ); } - public static Method getMethod( Class<?> clazz, String methodName, Class[] parameters ) + public static Method getMethod( Class<?> clazz, String methodName, Class<?>... parameters ) { try { @@ -54,7 +54,7 @@ public final class ReflectionUtils } } - public static Method tryGetMethod( Class<?> clazz, String methodName, Class[] parameters ) + public static Method tryGetMethod( Class<?> clazz, String methodName, Class<?>... parameters ) { try { @@ -72,7 +72,7 @@ public final class ReflectionUtils return invokeMethodWithArray( instance, method, NO_ARGS_VALUES ); } - public static Constructor getConstructor( Class<?> clazz, Class[] arguments ) + public static Constructor getConstructor( Class<?> clazz, Class<?>... arguments ) { try { @@ -84,7 +84,7 @@ public final class ReflectionUtils } } - public static Object newInstance( Constructor constructor, Object[] params ) + public static Object newInstance( Constructor constructor, Object... params ) { try { @@ -108,7 +108,7 @@ public final class ReflectionUtils { try { - Class clazz = loadClass( classLoader, classname ); + Class<?> clazz = loadClass( classLoader, classname ); return returnType.cast( clazz.newInstance() ); } catch ( InstantiationException e ) @@ -121,13 +121,13 @@ public final class ReflectionUtils } } - public static Object instantiateOneArg( ClassLoader classLoader, String className, Class param1Class, + public static Object instantiateOneArg( ClassLoader classLoader, String className, Class<?> param1Class, Object param1 ) { try { - Class aClass = loadClass( classLoader, className ); - Constructor constructor = ReflectionUtils.getConstructor( aClass, new Class[]{ param1Class } ); + Class<?> aClass = loadClass( classLoader, className ); + Constructor constructor = getConstructor( aClass, param1Class ); return constructor.newInstance( param1 ); } catch ( InvocationTargetException e ) @@ -144,13 +144,13 @@ public final class ReflectionUtils } } - public static Object instantiateTwoArgs( ClassLoader classLoader, String className, Class param1Class, + public static Object instantiateTwoArgs( ClassLoader classLoader, String className, Class<?> param1Class, Object param1, Class param2Class, Object param2 ) { try { - Class aClass = loadClass( classLoader, className ); - Constructor constructor = ReflectionUtils.getConstructor( aClass, new Class[]{ param1Class, param2Class } ); + Class<?> aClass = loadClass( classLoader, className ); + Constructor constructor = getConstructor( aClass, param1Class, param2Class ); return constructor.newInstance( param1, param2 ); } catch ( InvocationTargetException e ) @@ -167,19 +167,18 @@ public final class ReflectionUtils } } - - public static void invokeSetter( Object o, String name, Class value1clazz, Object value ) + public static void invokeSetter( Object o, String name, Class<?> value1clazz, Object value ) { - final Method setter = getMethod( o, name, new Class[]{ value1clazz } ); + Method setter = getMethod( o, name, value1clazz ); invokeSetter( o, setter, value ); } public static Object invokeSetter( Object target, Method method, Object value ) { - return invokeMethodWithArray( target, method, new Object[]{ value } ); + return invokeMethodWithArray( target, method, value ); } - public static Object invokeMethodWithArray( Object target, Method method, Object[] args ) + public static Object invokeMethodWithArray( Object target, Method method, Object... args ) { try { @@ -195,7 +194,7 @@ public final class ReflectionUtils } } - public static Object invokeMethodWithArray2( Object target, Method method, Object[] args ) + public static Object invokeMethodWithArray2( Object target, Method method, Object... args ) throws InvocationTargetException { try @@ -210,13 +209,13 @@ public final class ReflectionUtils public static Object instantiateObject( String className, Class[] types, Object[] params, ClassLoader classLoader ) { - Class clazz = loadClass( classLoader, className ); + Class<?> clazz = loadClass( classLoader, className ); final Constructor constructor = getConstructor( clazz, types ); return newInstance( constructor, params ); } @SuppressWarnings( "checkstyle:emptyblock" ) - public static Class tryLoadClass( ClassLoader classLoader, String className ) + public static Class<?> tryLoadClass( ClassLoader classLoader, String className ) { try { @@ -231,7 +230,7 @@ public final class ReflectionUtils return null; } - public static Class loadClass( ClassLoader classLoader, String className ) + public static Class<?> loadClass( ClassLoader classLoader, String className ) { try { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java index 85f9c45..a29eb14 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java @@ -26,7 +26,11 @@ import java.lang.reflect.Method; import org.apache.maven.surefire.providerapi.SurefireProvider; import org.apache.maven.surefire.suite.RunResult; import org.apache.maven.surefire.testset.TestSetFailedException; -import org.apache.maven.surefire.util.ReflectionUtils; + +import static org.apache.maven.surefire.util.ReflectionUtils.getMethod; +import static org.apache.maven.surefire.util.ReflectionUtils.invokeGetter; +import static org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray; +import static org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2; /** * Creates the surefire provider. @@ -48,6 +52,10 @@ public class ProviderFactory private static final Class[] INVOKE_PARAMETERS = { Object.class }; + private static final Class[] INVOKE_EMPTY_PARAMETER_TYPES = { }; + + private static final Class[] INVOKE_EMPTY_PARAMETERS = { }; + public ProviderFactory( StartupConfiguration startupConfiguration, ProviderConfiguration providerConfiguration, ClassLoader testsClassLoader, Object reporterManagerFactory ) { @@ -129,7 +137,7 @@ public class ProviderFactory ClassLoader current = swapClassLoader( testsClassLoader ); try { - return (Iterable<Class<?>>) ReflectionUtils.invokeGetter( providerInOtherClassLoader, "getSuites" ); + return (Iterable<Class<?>>) invokeGetter( providerInOtherClassLoader, "getSuites" ); } finally { @@ -143,11 +151,8 @@ public class ProviderFactory ClassLoader current = swapClassLoader( testsClassLoader ); try { - final Method invoke = - ReflectionUtils.getMethod( providerInOtherClassLoader.getClass(), "invoke", INVOKE_PARAMETERS ); - - final Object result = ReflectionUtils.invokeMethodWithArray2( providerInOtherClassLoader, invoke, - new Object[]{ forkTestSet } ); + Method invoke = getMethod( providerInOtherClassLoader.getClass(), "invoke", INVOKE_PARAMETERS ); + Object result = invokeMethodWithArray2( providerInOtherClassLoader, invoke, forkTestSet ); return (RunResult) surefireReflector.convertIfRunResult( result ); } finally @@ -169,9 +174,9 @@ public class ProviderFactory public void cancel() { - final Method invoke = - ReflectionUtils.getMethod( providerInOtherClassLoader.getClass(), "cancel", new Class[]{ } ); - ReflectionUtils.invokeMethodWithArray( providerInOtherClassLoader, invoke, null ); + Class<?> providerType = providerInOtherClassLoader.getClass(); + Method invoke = getMethod( providerType, "cancel", INVOKE_EMPTY_PARAMETER_TYPES ); + invokeMethodWithArray( providerInOtherClassLoader, invoke, INVOKE_EMPTY_PARAMETERS ); } } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3Reflector.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3Reflector.java b/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3Reflector.java index f343108..7c4a9cb 100644 --- a/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3Reflector.java +++ b/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3Reflector.java @@ -47,7 +47,7 @@ public final class JUnit3Reflector private final Class[] interfacesImplementedByDynamicProxy; - private final Class testResultClass; + private final Class<?> testResultClass; private final Method addListenerMethod; @@ -57,9 +57,9 @@ public final class JUnit3Reflector private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - private final Class testInterface; + private final Class<?> testInterface; - private final Class testCase; + private final Class<?> testCase; private final Constructor testsSuiteConstructor; @@ -70,9 +70,9 @@ public final class JUnit3Reflector testInterface = ReflectionUtils.tryLoadClass( testClassLoader, TEST ); interfacesImplementedByDynamicProxy = new Class[]{ ReflectionUtils.tryLoadClass( testClassLoader, TEST_LISTENER ) }; - Class[] constructorParamTypes = { Class.class }; + Class<?>[] constructorParamTypes = { Class.class }; - Class testSuite = ReflectionUtils.tryLoadClass( testClassLoader, TEST_SUITE ); + Class<?> testSuite = ReflectionUtils.tryLoadClass( testClassLoader, TEST_SUITE ); // The interface implemented by the dynamic proxy (TestListener), happens to be // the same as the param types of TestResult.addTestListener @@ -82,7 +82,7 @@ public final class JUnit3Reflector { testsSuiteConstructor = ReflectionUtils.getConstructor( testSuite, constructorParamTypes ); addListenerMethod = tryGetMethod( testResultClass, ADD_LISTENER_METHOD, addListenerParamTypes ); - testInterfaceRunMethod = getMethod( testInterface, RUN_METHOD, new Class[]{ testResultClass } ); + testInterfaceRunMethod = getMethod( testInterface, RUN_METHOD, testResultClass ); } else { @@ -93,7 +93,7 @@ public final class JUnit3Reflector } // Switch to reflectionutils when building with 2.7.2 - private static Method tryGetMethod( Class clazz, String methodName, Class[] parameters ) + private static Method tryGetMethod( Class<?> clazz, String methodName, Class<?>... parameters ) { try { @@ -105,7 +105,7 @@ public final class JUnit3Reflector } } - private static Method getMethod( Class clazz, String methodName, Class[] parameters ) + private static Method getMethod( Class<?> clazz, String methodName, Class<?>... parameters ) { try { @@ -125,9 +125,7 @@ public final class JUnit3Reflector if ( testObject == null && testCase.isAssignableFrom( testClass ) ) { - Object[] constructorParams = { testClass }; - - testObject = testsSuiteConstructor.newInstance( constructorParams ); + testObject = testsSuiteConstructor.newInstance( testClass ); } if ( testObject == null ) @@ -146,7 +144,7 @@ public final class JUnit3Reflector return testObject; } - private static Object createInstanceFromSuiteMethod( Class testClass ) + private static Object createInstanceFromSuiteMethod( Class<?> testClass ) throws IllegalAccessException, InvocationTargetException { Object testObject = null; @@ -166,19 +164,17 @@ public final class JUnit3Reflector return testObject; } - private static Constructor getTestConstructor( Class testClass ) + private static Constructor getTestConstructor( Class<?> testClass ) throws NoSuchMethodException { - Constructor constructor; try { - constructor = testClass.getConstructor( new Class[]{ String.class } ); + return testClass.getConstructor( String.class ); } catch ( NoSuchMethodException e ) { - constructor = testClass.getConstructor( EMPTY_CLASS_ARRAY ); + return testClass.getConstructor( EMPTY_CLASS_ARRAY ); } - return constructor; } public Class[] getInterfacesImplementedByDynamicProxy() @@ -186,7 +182,7 @@ public final class JUnit3Reflector return interfacesImplementedByDynamicProxy; } - public Class getTestResultClass() + public Class<?> getTestResultClass() { return testResultClass; } @@ -201,14 +197,14 @@ public final class JUnit3Reflector return testInterfaceRunMethod; } - public Class getTestInterface() + public Class<?> getTestInterface() { return testInterface; } - public Method getRunMethod( Class testClass ) + public Method getRunMethod( Class<?> testClass ) { - return getMethod( testClass, RUN_METHOD, new Class[]{ getTestResultClass() } ); + return getMethod( testClass, RUN_METHOD, getTestResultClass() ); } public boolean isJUnit3Available() http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3TestChecker.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3TestChecker.java b/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3TestChecker.java index 8042e16..f683714 100644 --- a/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3TestChecker.java +++ b/surefire-providers/common-junit3/src/main/java/org/apache/maven/surefire/common/junit3/JUnit3TestChecker.java @@ -36,7 +36,7 @@ import org.apache.maven.surefire.util.ScannerFilter; public class JUnit3TestChecker implements ScannerFilter { - private final Class junitClass; + private final Class<?> junitClass; private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; @@ -54,7 +54,7 @@ public class JUnit3TestChecker return nonAbstractClassFilter.accept( testClass ) && isValidJUnit3Test( testClass ); } - private boolean isValidJUnit3Test( Class testClass ) + private boolean isValidJUnit3Test( Class<?> testClass ) { return junitClass != null && ( junitClass.isAssignableFrom( testClass ) || isSuiteOnly( testClass ) ); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java index e43a71e..026e35d 100644 --- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java +++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4Reflector.java @@ -91,9 +91,8 @@ public final class JUnit4Reflector catch ( NoSuchMethodError e ) { Method method = tryGetMethod( Description.class, "createSuiteDescription", PARAMS_WITH_ANNOTATIONS ); - Object[] parameters = { description, new Annotation[0] }; // may throw exception probably with JUnit 5.x - return (Description) invokeMethodWithArray( null, method, parameters ); + return (Description) invokeMethodWithArray( null, method, description, new Annotation[0] ); } } @@ -102,7 +101,7 @@ public final class JUnit4Reflector Method method = tryGetMethod( Description.class, "createSuiteDescription", PARAMS_WITH_ANNOTATIONS ); return method == null ? Description.createSuiteDescription( description ) - : (Description) invokeMethodWithArray( null, method, new Object[] { description, annotations } ); + : (Description) invokeMethodWithArray( null, method, description, annotations ); } public static Ignore createIgnored( String value ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4TestChecker.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4TestChecker.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4TestChecker.java index 4996f64..c2a6c18 100644 --- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4TestChecker.java +++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4TestChecker.java @@ -42,9 +42,9 @@ public class JUnit4TestChecker public JUnit4TestChecker( ClassLoader testClassLoader ) { - this.jUnit3TestChecker = new JUnit3TestChecker( testClassLoader ); - this.runWith = tryLoadClass( testClassLoader, org.junit.runner.RunWith.class.getName() ); - this.nonAbstractClassFilter = new NonAbstractClassFilter(); + jUnit3TestChecker = new JUnit3TestChecker( testClassLoader ); + runWith = tryLoadClass( testClassLoader, org.junit.runner.RunWith.class.getName() ); + nonAbstractClassFilter = new NonAbstractClassFilter(); } public boolean accept( Class testClass ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java index 039a118..3878922 100644 --- a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java @@ -30,9 +30,9 @@ public final class JUnit48Reflector private static final String CATEGORY = "org.junit.experimental.categories.Category"; - private final Class categories; + private final Class<?> categories; - private final Class category; + private final Class<?> category; public JUnit48Reflector( ClassLoader testClassLoader ) { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java b/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java index e403a64..01bd54b 100644 --- a/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java +++ b/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java @@ -54,19 +54,19 @@ public class JUnit3Provider private final RunOrderCalculator runOrderCalculator; - private TestsToRun testsToRun; - private final ScanResult scanResult; + private TestsToRun testsToRun; + public JUnit3Provider( ProviderParameters booterParameters ) { this.providerParameters = booterParameters; - this.testClassLoader = booterParameters.getTestClassLoader(); - this.scanResult = booterParameters.getScanResult(); - this.runOrderCalculator = booterParameters.getRunOrderCalculator(); - this.reflector = new JUnit3Reflector( testClassLoader ); + testClassLoader = booterParameters.getTestClassLoader(); + scanResult = booterParameters.getScanResult(); + runOrderCalculator = booterParameters.getRunOrderCalculator(); + reflector = new JUnit3Reflector( testClassLoader ); jUnit3TestChecker = new JUnit3TestChecker( testClassLoader ); - this.testChecker = new PojoAndJUnit3Checker( jUnit3TestChecker ); // Todo; use reflector + testChecker = new PojoAndJUnit3Checker( jUnit3TestChecker ); // Todo; use reflector } public RunResult invoke( Object forkTestSet ) @@ -100,7 +100,7 @@ public class JUnit3Provider System.setSecurityManager( securityManager ); } - for ( Class clazz : testsToRun ) + for ( Class<?> clazz : testsToRun ) { SurefireTestSet surefireTestSet = createTestSet( clazz ); executeTestSet( surefireTestSet, reporter, testClassLoader ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java b/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java index 9fbc64b..919be7a 100644 --- a/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java +++ b/surefire-providers/surefire-junit3/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java @@ -74,13 +74,13 @@ public final class JUnitTestSet Object testObject = reflector.constructTestObject( testClass ); final Method runMethod; - if ( this.reflector.getTestInterface().isAssignableFrom( testObject.getClass() ) ) + if ( reflector.getTestInterface().isAssignableFrom( testObject.getClass() ) ) { - runMethod = this.reflector.getTestInterfaceRunMethod(); + runMethod = reflector.getTestInterfaceRunMethod(); } else { - runMethod = reflector.getRunMethod( this.testClass ); + runMethod = reflector.getRunMethod( testClass ); } Object instanceOfTestResult = reflector.getTestResultClass().newInstance(); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b586cef9/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java index 8401b22..b89ef8d 100644 --- a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java +++ b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java @@ -172,7 +172,7 @@ public class JUnit4Provider commandsReader.awaitStarted(); } - for ( Class aTestsToRun : testsToRun ) + for ( Class<?> aTestsToRun : testsToRun ) { executeTestSet( aTestsToRun, reporter, notifier ); }