Author: krosenvold Date: Thu Nov 11 16:25:51 2010 New Revision: 1033985 URL: http://svn.apache.org/viewvc?rev=1033985&view=rev Log: [SUREFIRE-482] Fixed overly constrained @RunWith test
Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestChecker.java maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4TestCheckerTest.java Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestChecker.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestChecker.java?rev=1033985&r1=1033984&r2=1033985&view=diff ============================================================================== --- maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestChecker.java (original) +++ maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestChecker.java Thu Nov 11 16:25:51 2010 @@ -33,12 +33,9 @@ public class JUnit4TestChecker private final Class runWith; - private final Class suite; - public JUnit4TestChecker( ClassLoader testClassLoader ) { this.junitClass = getJUnitClass( testClassLoader, junit.framework.Test.class.getName() ); - this.suite = getJUnitClass( testClassLoader, org.junit.runners.Suite.class.getName() ); this.runWith = getJUnitClass( testClassLoader, org.junit.runner.RunWith.class.getName() ); } @@ -51,14 +48,10 @@ public class JUnit4TestChecker return true; } - Annotation runWithAnno = testClass.getAnnotation( runWith ); - if ( runWithAnno != null ) + Annotation runWithAnnotation = testClass.getAnnotation( runWith ); + if ( runWithAnnotation != null ) { - final Class value = runWithValue( runWithAnno ); - if ( suite.isAssignableFrom( value ) ) - { - return true; - } + return true; } Class classToCheck = testClass; @@ -104,27 +97,4 @@ public class JUnit4TestChecker return junitClass; } - private Class runWithValue(Object object) - throws TestSetFailedException - { - final Method valueMethod; - try - { - valueMethod = object.getClass().getMethod( "value" ); - return (Class) valueMethod.invoke( object); - } - catch ( NoSuchMethodException e ) - { - throw new TestSetFailedException( e ); - } - catch ( InvocationTargetException e ) - { - throw new TestSetFailedException( e ); - } - catch ( IllegalAccessException e ) - { - throw new TestSetFailedException( e ); - } - } - } Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4TestCheckerTest.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4TestCheckerTest.java?rev=1033985&r1=1033984&r2=1033985&view=diff ============================================================================== --- maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4TestCheckerTest.java (original) +++ maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4TestCheckerTest.java Thu Nov 11 16:25:51 2010 @@ -22,7 +22,10 @@ import junit.framework.TestCase; import org.apache.maven.surefire.testset.TestSetFailedException; import org.junit.Test; import org.junit.internal.runners.InitializationError; +import org.junit.runner.Description; import org.junit.runner.RunWith; +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; import org.junit.runners.Suite; import static org.junit.Assert.assertFalse; @@ -70,6 +73,13 @@ public class JUnit4TestCheckerTest } @Test + public void validCustomRunner() + throws TestSetFailedException + { + assertTrue( jUnit4TestChecker.isValidJUnit4Test( SuiteValidCustomRunner.class ) ); + } + + @Test public void invalidTest() throws TestSetFailedException { @@ -113,6 +123,30 @@ public class JUnit4TestCheckerTest } } + class CustomRunner + extends Runner { + @Override + public Description getDescription() + { + return Description.createSuiteDescription( "CustomRunner" ); + } + + @Override + public void run( RunNotifier runNotifier ) + { + } + } + + @RunWith(CustomRunner.class) + public static class SuiteValidCustomRunner + { + public void testSomething() + { + + } + } + + @RunWith(MySuite.class) public static class SuiteValid2 {