maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agud...@apache.org
Subject git commit: [SUREFIRE-971] allow combining test method pattern and group pattern
Date Mon, 18 Mar 2013 22:34:34 GMT
Updated Branches:
  refs/heads/master c513cbc5b -> 81e39803d


[SUREFIRE-971] allow combining test method pattern and group pattern


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/81e39803
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/81e39803
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/81e39803

Branch: refs/heads/master
Commit: 81e39803d8f2724719b2eeb36cf0639de973f225
Parents: c513cbc
Author: Andreas Gudian <agudian@apache.org>
Authored: Mon Mar 18 23:31:43 2013 +0100
Committer: Andreas Gudian <agudian@apache.org>
Committed: Mon Mar 18 23:31:43 2013 +0100

----------------------------------------------------------------------
 .../maven/surefire/its/TestMethodPatternIT.java    |    6 +
 .../src/test/java/junit4/BasicTest.java            |    2 +
 .../src/test/java/junit4/SampleCategory.java       |    6 +
 .../surefire/common/junit48/FilterFactory.java     |   77 +++++++++++----
 .../surefire/junitcore/JUnitCoreProvider.java      |   26 +++---
 5 files changed, 83 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/81e39803/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMethodPatternIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMethodPatternIT.java
b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMethodPatternIT.java
index aedb953..8438dd2 100644
--- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMethodPatternIT.java
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestMethodPatternIT.java
@@ -48,6 +48,12 @@ public class TestMethodPatternIT
     }
 
     @Test
+    public void testJUnit48WithCategoryFilter()
+    {
+        unpack( "junit48-method-pattern" ).addGoal( "-Dgroups=junit4.SampleCategory" ).executeTest().assertTestSuiteResults(
1, 0, 0, 0 );;
+    }
+
+    @Test
     public void testTestNgMethodBefore()
     {
         runMethodPattern( "testng-method-pattern-before" );

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/81e39803/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/BasicTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/BasicTest.java
b/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/BasicTest.java
index f5d0b9f..6d883af 100644
--- a/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/BasicTest.java
+++ b/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/BasicTest.java
@@ -4,6 +4,7 @@ import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 
 public class BasicTest
@@ -43,6 +44,7 @@ public class BasicTest
     } 
     
     @Test
+    @Category(SampleCategory.class)
     public void testSuccessTwo()
     {
         Assert.assertTrue( true );

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/81e39803/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/SampleCategory.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/SampleCategory.java
b/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/SampleCategory.java
new file mode 100644
index 0000000..9a8c4fe
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/junit48-method-pattern/src/test/java/junit4/SampleCategory.java
@@ -0,0 +1,6 @@
+package junit4;
+
+public interface SampleCategory
+{
+
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/81e39803/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java
b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java
index ed770f6..ff30e18 100644
--- a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java
+++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java
@@ -65,8 +65,8 @@ public class FilterFactory
             }
             catch ( ParseException e )
             {
-                throw new IllegalArgumentException(
-                    "Invalid group expression: '" + groups + "'. Reason: " + e.getMessage(),
e );
+                throw new IllegalArgumentException( "Invalid group expression: '" + groups
+ "'. Reason: "
+                    + e.getMessage(), e );
             }
         }
 
@@ -79,13 +79,14 @@ public class FilterFactory
             }
             catch ( ParseException e )
             {
-                throw new IllegalArgumentException(
-                    "Invalid group expression: '" + excludedGroups + "'. Reason: " + e.getMessage(),
e );
+                throw new IllegalArgumentException( "Invalid group expression: '" + excludedGroups
+ "'. Reason: "
+                    + e.getMessage(), e );
             }
         }
 
         // GroupMatcher included = commaSeparatedListToFilters( groups );
-        // GroupMatcher excluded = commaSeparatedListToFilters( excludedGroups );
+        // GroupMatcher excluded = commaSeparatedListToFilters( excludedGroups
+        // );
 
         if ( included != null && testClassLoader != null )
         {
@@ -120,7 +121,8 @@ public class FilterFactory
     // }
     // catch ( ParseException e )
     // {
-    // throw new IllegalArgumentException( "Invalid group expression: '" + group + "'. Reason:
"
+    // throw new IllegalArgumentException( "Invalid group expression: '" + group
+    // + "'. Reason: "
     // + e.getMessage(), e );
     // }
     //
@@ -137,6 +139,11 @@ public class FilterFactory
         return new MethodFilter( requestedTestMethod );
     }
 
+    public Filter and( Filter filter1, Filter filter2 )
+    {
+        return new AndFilter( filter1, filter2 );
+    }
+
     private static class MethodFilter
         extends Filter
     {
@@ -163,11 +170,10 @@ public class FilterFactory
 
         private boolean isDescriptionMatch( Description description )
         {
-            return description.getMethodName() != null && SelectorUtils.match( requestedTestMethod,
-                                                                               description.getMethodName()
);
+            return description.getMethodName() != null
+                && SelectorUtils.match( requestedTestMethod, description.getMethodName()
);
         }
 
-
         @Override
         public String describe()
         {
@@ -204,9 +210,9 @@ public class FilterFactory
         @Override
         public boolean shouldRun( Description description )
         {
-            return shouldRun( description, ( description.getMethodName() == null
-                ? null
-                : Description.createSuiteDescription( description.getTestClass() ) ) );
+            return shouldRun( description,
+                              ( description.getMethodName() == null ? null
+                                              : Description.createSuiteDescription( description.getTestClass()
) ) );
         }
 
         private boolean shouldRun( Description description, Description parent )
@@ -230,7 +236,8 @@ public class FilterFactory
             Category cat = description.getAnnotation( Category.class );
             if ( cat != null )
             {
-                // System.out.println( "Adding categories: " + Arrays.toString( cat.value()
) );
+                // System.out.println( "Adding categories: " + Arrays.toString(
+                // cat.value() ) );
                 cats.addAll( Arrays.asList( cat.value() ) );
             }
 
@@ -239,21 +246,26 @@ public class FilterFactory
                 cat = parent.getAnnotation( Category.class );
                 if ( cat != null )
                 {
-                    // System.out.println( "Adding class-level categories: " + Arrays.toString(
cat.value() ) );
+                    // System.out.println( "Adding class-level categories: " +
+                    // Arrays.toString( cat.value() ) );
                     cats.addAll( Arrays.asList( cat.value() ) );
                 }
             }
 
-            // System.out.println( "Checking " + cats.size() + " categories..." );
+            // System.out.println( "Checking " + cats.size() + " categories..."
+            // );
             //
-            // System.out.println( "Enabled? " + ( matcher.enabled( cats.toArray( new Class<?>[]
{} ) ) ) + "\n\n" );
-            result = matcher.enabled( cats.toArray( new Class<?>[]{ } ) );
+            // System.out.println( "Enabled? " + ( matcher.enabled(
+            // cats.toArray( new Class<?>[] {} ) ) ) + "\n\n" );
+            result = matcher.enabled( cats.toArray( new Class<?>[] {} ) );
 
             if ( parent == null )
             {
                 if ( cats.size() == 0 )
                 {
-                    // System.out.println( "Allow method-level filtering by PASSing class-level
shouldRun() test..." );
+                    // System.out.println(
+                    // "Allow method-level filtering by PASSing class-level shouldRun() test..."
+                    // );
                     result = true;
                 }
                 else if ( !result )
@@ -285,6 +297,31 @@ public class FilterFactory
 
     }
 
+    private static class AndFilter
+        extends Filter
+    {
+        private final Filter filter1;
+
+        private final Filter filter2;
+
+        public AndFilter( Filter filter1, Filter filter2 )
+        {
+            this.filter1 = filter1;
+            this.filter2 = filter2;
+        }
+
+        @Override
+        public boolean shouldRun( Description description )
+        {
+            return filter1.shouldRun( description ) && filter2.shouldRun( description
);
+        }
+
+        @Override
+        public String describe()
+        {
+            return filter1.describe() + " AND " + filter2.describe();
+        }
+    }
 
     @SuppressWarnings( "unused" )
     private static class CombinedCategoryFilter
@@ -303,8 +340,8 @@ public class FilterFactory
         @Override
         public boolean shouldRun( Description description )
         {
-            return ( includedFilters.isEmpty() || inOneOfFilters( includedFilters, description
) ) && (
-                excludedFilters.isEmpty() || !inOneOfFilters( excludedFilters, description
) );
+            return ( includedFilters.isEmpty() || inOneOfFilters( includedFilters, description
) )
+                && ( excludedFilters.isEmpty() || !inOneOfFilters( excludedFilters,
description ) );
         }
 
         private boolean inOneOfFilters( List<Filter> filters, Description description
)

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/81e39803/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
index 55d0edf..075216d 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
@@ -62,7 +62,6 @@ public class JUnitCoreProvider
 
     private final ProviderParameters providerParameters;
 
-
     private TestsToRun testsToRun;
 
     private JUnit48Reflector jUnit48Reflector;
@@ -83,8 +82,8 @@ public class JUnitCoreProvider
         this.scannerFilter = new JUnit4TestChecker( testClassLoader );
         this.requestedTestMethod = providerParameters.getTestRequest().getRequestedTestMethod();
 
-        customRunListeners = JUnit4RunListenerFactory.
-            createCustomListeners( providerParameters.getProviderProperties().getProperty(
"listener" ) );
+        customRunListeners =
+            JUnit4RunListenerFactory.createCustomListeners( providerParameters.getProviderProperties().getProperty(
"listener" ) );
         jUnit48Reflector = new JUnit48Reflector( testClassLoader );
     }
 
@@ -95,18 +94,16 @@ public class JUnitCoreProvider
 
     public Iterator getSuites()
     {
-        final Filter filter = jUnit48Reflector.isJUnit48Available() ? createJUnit48Filter()
: null;
         testsToRun = scanClassPath();
         return testsToRun.iterator();
     }
 
     private boolean isSingleThreaded()
     {
-        return !jUnitCoreParameters.isAnyParallelitySelected() || ( testsToRun.containsExactly(
1 )
-            && !jUnitCoreParameters.isParallelMethod() );
+        return !jUnitCoreParameters.isAnyParallelitySelected()
+            || ( testsToRun.containsExactly( 1 ) && !jUnitCoreParameters.isParallelMethod()
);
     }
 
-
     public RunResult invoke( Object forkTestSet )
         throws TestSetFailedException, ReporterException
     {
@@ -157,10 +154,10 @@ public class JUnitCoreProvider
         {
             final Map<String, TestSet> testSetMap = new ConcurrentHashMap<String,
TestSet>();
 
-            RunListener listener = ConcurrentRunListener.createInstance( testSetMap, reporterFactory,
-                                                                         jUnitCoreParameters.isParallelClasses(),
-                                                                         jUnitCoreParameters.isParallelBoth(),
-                                                                         consoleLogger );
+            RunListener listener =
+                ConcurrentRunListener.createInstance( testSetMap, reporterFactory,
+                                                      jUnitCoreParameters.isParallelClasses(),
+                                                      jUnitCoreParameters.isParallelBoth(),
consoleLogger );
             ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) listener );
 
             jUnit4RunListener = new JUnitCoreRunListener( listener, testSetMap );
@@ -171,9 +168,10 @@ public class JUnitCoreProvider
     private Filter createJUnit48Filter()
     {
         final FilterFactory filterFactory = new FilterFactory( testClassLoader );
-        return isMethodFilterSpecified()
-            ? filterFactory.createMethodFilter( requestedTestMethod )
-            : filterFactory.createGroupFilter( providerParameters.getProviderProperties()
);
+        Filter groupFilter = filterFactory.createGroupFilter( providerParameters.getProviderProperties()
);
+        return isMethodFilterSpecified() ? filterFactory.and( groupFilter,
+                                                              filterFactory.createMethodFilter(
requestedTestMethod ) )
+                        : groupFilter;
     }
 
     private TestsToRun scanClassPath()


Mime
View raw message