You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by br...@apache.org on 2006/03/03 08:58:01 UTC
svn commit: r382711 - in /maven/surefire/branches/surefire-testng:
surefire-api/src/main/java/org/apache/maven/surefire/suite/
surefire-api/src/test/java/org/apache/maven/surefire/
surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefi...
Author: brett
Date: Thu Mar 2 23:57:59 2006
New Revision: 382711
URL: http://svn.apache.org/viewcvs?rev=382711&view=rev
Log:
[MSUREFIRE-23] clean up abstract test set
Modified:
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/POJOTest.java
maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java?rev=382711&r1=382710&r2=382711&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java Thu Mar 2 23:57:59 2006
@@ -37,6 +37,7 @@
public abstract class AbstractDirectoryTestSuite
implements SurefireTestSuite
{
+ // TODO: fix this
private ResourceBundle bundle = ResourceBundle.getBundle( "org.apache.maven.surefire.surefire" );
private static final String FS = System.getProperty( "file.separator" );
@@ -104,7 +105,8 @@
return Collections.unmodifiableMap( testSets );
}
- protected abstract SurefireTestSet createTestSet( Class testClass );
+ protected abstract SurefireTestSet createTestSet( Class testClass )
+ throws TestSetFailedException;
public void execute( ReporterManager reporterManager, ClassLoader classLoader )
throws ReporterException, TestSetFailedException
Modified: maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/POJOTest.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/POJOTest.java?rev=382711&r1=382710&r2=382711&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/POJOTest.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/test/java/org/apache/maven/surefire/POJOTest.java Thu Mar 2 23:57:59 2006
@@ -1,4 +1,6 @@
-package org.apache.maven.surefire;/*
+package org.apache.maven.surefire;
+
+/*
* Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java?rev=382711&r1=382710&r2=382711&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java Thu Mar 2 23:57:59 2006
@@ -18,6 +18,7 @@
import org.apache.maven.surefire.suite.AbstractDirectoryTestSuite;
import org.apache.maven.surefire.testset.SurefireTestSet;
+import org.apache.maven.surefire.testset.TestSetFailedException;
import java.io.File;
import java.util.ArrayList;
@@ -36,6 +37,7 @@
}
protected SurefireTestSet createTestSet( Class testClass )
+ throws TestSetFailedException
{
return new JUnitTestSet( testClass );
}
Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java?rev=382711&r1=382710&r2=382711&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java Thu Mar 2 23:57:59 2006
@@ -69,6 +69,7 @@
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
public JUnitTestSet( Class testClass )
+ throws TestSetFailedException
{
if ( testClass == null )
{
@@ -76,115 +77,92 @@
}
this.testClass = testClass;
+
+ processTestClass( testClass.getClassLoader() );
}
- private void processTestClass( ClassLoader loader )
- throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException,
- NoSuchMethodException
+ public Class getTestClass()
{
- testResultClass = loader.loadClass( TEST_RESULT );
-
- Class testCaseClass = loader.loadClass( TEST_CASE );
-
- Class testSuiteClass = loader.loadClass( TEST_SUITE );
-
- Class testListenerInterface = loader.loadClass( TEST_LISTENER );
-
- Class testInterface = loader.loadClass( TEST );
-
- // ----------------------------------------------------------------------
- // Strategy for executing JUnit tests
- //
- // o look for the suite method and if that is present execute that method
- // to get the test object.
- //
- // o look for test classes that are assignable from TestCase
- //
- // o look for test classes that only implement the Test interface
- // ----------------------------------------------------------------------
+ return testClass;
+ }
- Object testObject = null;
+ private void processTestClass( ClassLoader loader )
+ throws TestSetFailedException
+ {
try
{
- Method suiteMethod = testClass.getMethod( "suite", EMPTY_CLASS_ARRAY );
+ testResultClass = loader.loadClass( TEST_RESULT );
- if ( Modifier.isPublic( suiteMethod.getModifiers() ) && Modifier.isStatic( suiteMethod.getModifiers() ) )
- {
- testObject = suiteMethod.invoke( null, EMPTY_CLASS_ARRAY );
- }
- }
- catch ( NoSuchMethodException e )
- {
- // No suite method
- }
+ Class testCaseClass = loader.loadClass( TEST_CASE );
- if ( testObject == null && testCaseClass.isAssignableFrom( testClass ) )
- {
- Class[] constructorParamTypes = {Class.class};
+ Class testSuiteClass = loader.loadClass( TEST_SUITE );
- Constructor constructor = testSuiteClass.getConstructor( constructorParamTypes );
+ Class testListenerInterface = loader.loadClass( TEST_LISTENER );
- Object[] constructorParams = {testClass};
+ Class testInterface = loader.loadClass( TEST );
- testObject = constructor.newInstance( constructorParams );
- }
+ // ----------------------------------------------------------------------
+ // Strategy for executing JUnit tests
+ //
+ // o look for the suite method and if that is present execute that method
+ // to get the test object.
+ //
+ // o look for test classes that are assignable from TestCase
+ //
+ // o look for test classes that only implement the Test interface
+ // ----------------------------------------------------------------------
- if ( testObject == null )
- {
- Constructor testConstructor = getTestConstructor( testClass );
+ Object testObject = createInstanceFromSuiteMethod();
- if ( testConstructor.getParameterTypes().length == 0 )
- {
- testObject = testConstructor.newInstance( EMPTY_OBJECT_ARRAY );
- }
- else
+ if ( testObject == null && testCaseClass.isAssignableFrom( testClass ) )
{
- testObject = testConstructor.newInstance( new Object[]{testClass.getName()} );
- }
- }
- this.testObject = testObject;
+ Class[] constructorParamTypes = {Class.class};
- interfacesImplementedByDynamicProxy = new Class[1];
+ Constructor constructor = testSuiteClass.getConstructor( constructorParamTypes );
- interfacesImplementedByDynamicProxy[0] = testListenerInterface;
+ Object[] constructorParams = {testClass};
- // The interface implemented by the dynamic proxy (TestListener), happens to be
- // the same as the param types of TestResult.addTestListener
- Class[] addListenerParamTypes = interfacesImplementedByDynamicProxy;
+ testObject = constructor.newInstance( constructorParams );
+ }
- addListenerMethod = testResultClass.getMethod( ADD_LISTENER_METHOD, addListenerParamTypes );
+ if ( testObject == null )
+ {
+ Constructor testConstructor = getTestConstructor( testClass );
- if ( testInterface.isAssignableFrom( testClass ) )//testObject.getClass() ) )
- {
- countTestCasesMethod = testInterface.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
+ if ( testConstructor.getParameterTypes().length == 0 )
+ {
+ testObject = testConstructor.newInstance( EMPTY_OBJECT_ARRAY );
+ }
+ else
+ {
+ testObject = testConstructor.newInstance( new Object[]{testClass.getName()} );
+ }
+ }
+ this.testObject = testObject;
- runMethod = testInterface.getMethod( RUN_METHOD, new Class[]{testResultClass} );
+ interfacesImplementedByDynamicProxy = new Class[1];
- }
- else
- {
- countTestCasesMethod = testClass.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
+ interfacesImplementedByDynamicProxy[0] = testListenerInterface;
- runMethod = testClass.getMethod( RUN_METHOD, new Class[]{testResultClass} );
- }
- }
+ // The interface implemented by the dynamic proxy (TestListener), happens to be
+ // the same as the param types of TestResult.addTestListener
+ Class[] addListenerParamTypes = interfacesImplementedByDynamicProxy;
- public Class getTestClass()
- {
- return testClass;
- }
+ addListenerMethod = testResultClass.getMethod( ADD_LISTENER_METHOD, addListenerParamTypes );
- protected Object getTestClassInstance()
- {
- return testObject;
- }
+ if ( testInterface.isAssignableFrom( testClass ) )//testObject.getClass() ) )
+ {
+ countTestCasesMethod = testInterface.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
- public void execute( ReporterManager reportManager, ClassLoader loader )
- throws TestSetFailedException
- {
- try
- {
- processTestClass( loader );
+ runMethod = testInterface.getMethod( RUN_METHOD, new Class[]{testResultClass} );
+
+ }
+ else
+ {
+ countTestCasesMethod = testClass.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
+
+ runMethod = testClass.getMethod( RUN_METHOD, new Class[]{testResultClass} );
+ }
}
catch ( ClassNotFoundException e )
{
@@ -206,11 +184,29 @@
{
throw new TestSetFailedException( "Class is not a JUnit TestCase", e );
}
+ }
+
+ private Object createInstanceFromSuiteMethod()
+ throws IllegalAccessException, InvocationTargetException
+ {
+ Object testObject = null;
+ try
+ {
+ Method suiteMethod = testClass.getMethod( "suite", EMPTY_CLASS_ARRAY );
- executeJUnit( reportManager, loader );
+ if ( Modifier.isPublic( suiteMethod.getModifiers() ) && Modifier.isStatic( suiteMethod.getModifiers() ) )
+ {
+ testObject = suiteMethod.invoke( null, EMPTY_CLASS_ARRAY );
+ }
+ }
+ catch ( NoSuchMethodException e )
+ {
+ // No suite method
+ }
+ return testObject;
}
- private void executeJUnit( ReporterManager reportManager, ClassLoader classLoader )
+ public void execute( ReporterManager reportManager, ClassLoader loader )
throws TestSetFailedException
{
try
@@ -218,10 +214,10 @@
Object instanceOfTestResult = testResultClass.newInstance();
TestListenerInvocationHandler invocationHandler =
- new TestListenerInvocationHandler( reportManager, instanceOfTestResult, classLoader );
+ new TestListenerInvocationHandler( reportManager, instanceOfTestResult, loader );
Object testListener =
- Proxy.newProxyInstance( classLoader, interfacesImplementedByDynamicProxy, invocationHandler );
+ Proxy.newProxyInstance( loader, interfacesImplementedByDynamicProxy, invocationHandler );
Object[] addTestListenerParams = {testListener};