Author: krosenvold
Date: Thu Nov 10 20:52:07 2011
New Revision: 1200541

URL: http://svn.apache.org/viewvc?rev=1200541&view=rev
Log:
[SUREFIRE-786] @Category not taken into account for forkMode=always

Testcase and initial patch by nkeywal. Extended fix to cover method-level
categories in 'always' forks too.

This also fixes a quite serious issue of custom provider properties
not making it into the provider upon forkMode=always, which
should close quite a few other issues too

Modified:
    
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
    
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java
    
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java

Modified: 
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java?rev=1200541&r1=1200540&r2=1200541&view=diff
==============================================================================
--- 
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
 (original)
+++ 
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
 Thu Nov 10 20:52:07 2011
@@ -99,7 +99,7 @@ public class ForkStarter
             }
             else if ( ForkConfiguration.FORK_ALWAYS.equals( requestedForkMode 
) )
             {
-                result = runSuitesForkPerTestSet( fileReporterFactory );
+                result = runSuitesForkPerTestSet( fileReporterFactory, 
providerConfiguration.getProviderProperties() );
             }
             else
             {
@@ -113,15 +113,13 @@ public class ForkStarter
         return result;
     }
 
-    private RunResult runSuitesForkPerTestSet( FileReporterFactory 
fileReporterFactory )
+    private RunResult runSuitesForkPerTestSet( FileReporterFactory 
fileReporterFactory, Properties properties )
         throws SurefireBooterForkException
     {
         RunResult globalResult = new RunResult( 0, 0, 0, 0 );
 
         final Iterator suites = getSuitesIterator();
 
-        Properties properties = new Properties();
-
         while ( suites.hasNext() )
         {
             Object testSet = suites.next();

Modified: 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java?rev=1200541&r1=1200540&r2=1200541&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java
 (original)
+++ 
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java
 Thu Nov 10 20:52:07 2011
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.its;
  */
 
 
+import org.apache.maven.it.VerificationException;
+
 /**
  * Test project using "groups" support
  *
@@ -35,6 +37,19 @@ public class JUnit48TestCategoriesIT
     public void testCategoriesAB()
         throws Exception
     {
+        runAB();
+    }
+
+    public void testCategoriesABForkAlways()
+        throws Exception
+    {
+        forkAlways();
+        runAB();
+    }
+
+    private void runAB()
+        throws VerificationException
+    {
         executeTest();
         verifyErrorFreeLog();
         assertTestSuiteResults( 2, 0, 0, 0 );
@@ -47,6 +62,20 @@ public class JUnit48TestCategoriesIT
     public void testCategoriesAC()
         throws Exception
     {
+        runAC();
+    }
+
+    public void testCategoriesACForkAlways()
+        throws Exception
+    {
+        forkAlways();
+        runAC();
+    }
+
+
+    private void runAC()
+        throws Exception
+    {
         addGoal( "-Dgroups=junit4.CategoryA,junit4.CategoryC" );
         executeTest();
         verifyErrorFreeLog();
@@ -60,4 +89,5 @@ public class JUnit48TestCategoriesIT
         verifyTextInLog("mC: 1");
         verifyTextInLog("CatNone: 1");
     }
+
 }

Modified: 
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
URL: 
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java?rev=1200541&r1=1200540&r2=1200541&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
 (original)
+++ 
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
 Thu Nov 10 20:52:07 2011
@@ -87,7 +87,8 @@ public class JUnitCoreProvider
 
     public Iterator getSuites()
     {
-        testsToRun = scanClassPath();
+        final Filter filter = jUnit48Reflector.isJUnit48Available() ? 
createJUnit48Filter() : null;
+        testsToRun = getSuitesAsList( filter );
         return testsToRun.iterator();
     }
 
@@ -127,13 +128,17 @@ public class JUnitCoreProvider
     {
         List<Class<?>> res = new ArrayList<Class<?>>( 500 );
         TestsToRun max = scanClassPath();
+        if (filter == null){
+            return max;
+        }
+
         Iterator<Class<?>> it = max.iterator();
         while ( it.hasNext() )
         {
             Class<?> clazz = it.next();
             boolean isCategoryAnnotatedClass = 
jUnit48Reflector.isCategoryAnnotationPresent( clazz);
             Description d = Description.createSuiteDescription( clazz );
-            if ( !isCategoryAnnotatedClass || filter == null || 
filter.shouldRun( d ) )
+            if ( !isCategoryAnnotatedClass || filter.shouldRun( d ) )
             {
                 res.add( clazz );
             }


Reply via email to