Skip to content

Commit

Permalink
Match class names by first converting to a path pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorstmann committed Dec 21, 2014
1 parent a439d07 commit bbf9b25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
Expand Up @@ -119,52 +119,38 @@ private static class MethodFilter

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 )
{
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;
Expand All @@ -181,8 +167,9 @@ public MethodFilter( String requestString )

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
Expand Down
Expand Up @@ -112,17 +112,9 @@ public void shouldMatchExactClassAndMethod()
}

@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 ) );
}
Expand Down

0 comments on commit bbf9b25

Please sign in to comment.