You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2015/03/26 01:15:46 UTC

[04/19] maven-surefire git commit: Match class names by first converting to a path pattern

Match class names by first converting to a path 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/bbf9b251
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/bbf9b251
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/bbf9b251

Branch: refs/heads/master
Commit: bbf9b25189ca4a87db3cb2573b3715ed554557f1
Parents: a439d07
Author: Jörn Horstmann <gi...@jhorstmann.net>
Authored: Sun Dec 21 15:34:33 2014 +0100
Committer: Jörn Horstmann <gi...@jhorstmann.net>
Committed: Sun Dec 21 15:34:33 2014 +0100

----------------------------------------------------------------------
 .../surefire/common/junit48/FilterFactory.java  | 43 +++++++-------------
 .../common/junit48/FilterFactoryTest.java       | 12 +-----
 2 files changed, 17 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/bbf9b251/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 dbab6dd..3f81f87 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
@@ -119,18 +119,19 @@ public class FilterFactory
 
         private static class RequestedTestMethod
         {
-            final String className;
-            final String methodName;
+            final String classPattern;
+            final String methodPattern;
 
             private RequestedTestMethod( String className, String methodName )
             {
-                this.className = className;
-                this.methodName = methodName;
+                // convert to path pattern so we can use the same matching logic as in includes
+                this.classPattern = className == null ? null : "**/" + convertToPath( className );
+                this.methodPattern = methodName;
             }
 
-            private static boolean isSelectorPattern( String pattern )
+            private static String convertToPath( String className )
             {
-                return pattern.contains( "*" ) || pattern.contains( "?" );
+                return className.replace( '.', '/' );
             }
 
             public boolean isDescriptionmatch( Description description )
@@ -138,33 +139,18 @@ public class FilterFactory
                 String describedClassName = description.getClassName();
                 String describedMethodName = description.getMethodName();
 
-                if ( methodName != null )
+                if ( methodPattern != null )
                 {
-                    if ( describedMethodName == null || !SelectorUtils.match( methodName, describedMethodName ) )
+                    if ( describedMethodName == null || !SelectorUtils.match( methodPattern, describedMethodName ) )
                     {
                         return false;
                     }
                 }
 
-                if ( className != null && describedClassName != null )
+                if ( classPattern != null && describedClassName != null )
                 {
-                    if ( !isSelectorPattern( className ) )
-                    {
-                        // existing implementation seems to be a simple contains check
-                        if ( describedClassName.contains( className ) )
-                        {
-                            return true;
-                        }
-                    }
-                    else
-                    {
-                        if ( SelectorUtils.match( className, describedClassName ) )
-                        {
-                            return true;
-                        }
-                    }
-
-                    return false;
+                    String describedPath = convertToPath( describedClassName );
+                    return SelectorUtils.matchPath( classPattern, describedPath );
                 }
 
                 return true;
@@ -181,8 +167,9 @@ public class FilterFactory
 
             if ( !requestString.contains( "#" ) )
             {
-                // old way before SUREFIRE-745, filter only by method name
-                // class name filtering is done separately
+                // a single method was specified, the leading hash sign was split off by
+                // {@link org.apache.maven.plugin.surefire.SurefirePlugin#getTestMethod()}
+                // filtering by class name is done via modified includes also in SurefirePlugin
                 requestedTestMethods.add( new RequestedTestMethod( null, requestString ) );
             }
             else

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/bbf9b251/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java b/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java
index bf9dd98..f44ee0a 100644
--- a/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java
+++ b/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/FilterFactoryTest.java
@@ -112,17 +112,9 @@ public class FilterFactoryTest
     }
 
     @Test
-    public void shouldMatchEndOfClassNameWithMethod()
+    public void shouldMatchSimpleClassNameWithMethod()
     {
-        Filter exactFilter = createMethodFilter( "FirstClass#testMethod" );
-        assertTrue( "exact match on name should run", exactFilter.shouldRun( testMethod ) );
-        assertFalse( "other method should not match", exactFilter.shouldRun( otherMethod ) );
-    }
-
-    @Test
-    public void shouldMatchPartialClassNameWithMethod()
-    {
-        Filter exactFilter = createMethodFilter( "FirstClass#testMethod" );
+        Filter exactFilter = createMethodFilter( "FilterFactoryTest$FirstClass#testMethod" );
         assertTrue( "exact match on name should run", exactFilter.shouldRun( testMethod ) );
         assertFalse( "other method should not match", exactFilter.shouldRun( otherMethod ) );
     }