diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/TestListResolver.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/TestListResolver.java index bae7c2924d..b10223a205 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/TestListResolver.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/testset/TestListResolver.java @@ -49,10 +49,6 @@ public class TestListResolver { private static final String JAVA_CLASS_FILE_EXTENSION = ".class"; - private static final TestListResolver WILDCARD = new TestListResolver( "*" + JAVA_CLASS_FILE_EXTENSION ); - - private static final TestListResolver EMPTY = new TestListResolver( "" ); - private final Set includedPatterns; private final Set excludedPatterns; @@ -135,27 +131,6 @@ public boolean hasMethodPatterns() return hasIncludedMethodPatterns() || hasExcludedMethodPatterns(); } - /** - * - * @param resolver filter possibly having method patterns - * @return {@code resolver} if {@link TestListResolver#hasMethodPatterns() resolver.hasMethodPatterns()} - * returns {@code true}; Otherwise wildcard filter {@code *.class} is returned. - */ - public static TestListResolver optionallyWildcardFilter( TestListResolver resolver ) - { - return resolver.hasMethodPatterns() ? resolver : WILDCARD; - } - - public static TestListResolver getEmptyTestListResolver() - { - return EMPTY; - } - - public final boolean isWildcard() - { - return equals( WILDCARD ); - } - public TestFilter and( final TestListResolver another ) { return new TestFilter() @@ -238,7 +213,7 @@ public boolean shouldRun( String testClassFile, String methodName ) @Override public boolean isEmpty() { - return equals( EMPTY ); + return includedPatterns.isEmpty() && excludedPatterns.isEmpty(); } @Override diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/TestListResolverTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/TestListResolverTest.java index 8ca9753a45..a4a5a1ff1b 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/TestListResolverTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/api/testset/TestListResolverTest.java @@ -19,8 +19,6 @@ * under the License. */ -import junit.framework.TestCase; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -29,12 +27,14 @@ import java.util.LinkedHashSet; import java.util.Set; -import static java.util.Collections.addAll; -import static org.apache.maven.surefire.api.testset.TestListResolver.newTestListResolver; -import static org.apache.maven.surefire.api.testset.ResolvedTest.Type.CLASS; +import junit.framework.TestCase; + import static java.util.Arrays.asList; +import static java.util.Collections.addAll; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; +import static org.apache.maven.surefire.api.testset.ResolvedTest.Type.CLASS; +import static org.apache.maven.surefire.api.testset.TestListResolver.newTestListResolver; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -231,6 +231,7 @@ public void testResolveTestRequest() assertFalse( excludedFilters.isEmpty() ); assertEquals( 1, excludedFilters.size() ); ResolvedTest test = excludedFilters.iterator().next(); + assertTrue( test.hasTestMethodPattern() ); // ResolvedTest should not care about isExcluded. This attribute is handled by TestListResolver. assertTrue( test.matchAsInclusive( "pkg/MyTest.class", "myTest" ) ); assertFalse( test.matchAsInclusive( "pkg/MyTest.class", "otherTest" ) ); @@ -245,19 +246,21 @@ public void testShouldRunTestWithoutMethod() public void testShouldNotRunExcludedMethods() { + // shouldRun method is null - method pattern test ??? TestListResolver resolver = new TestListResolver( "!#*Fail*, !%regex[#.*One], !#testSuccessThree" ); assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) ); } public void testShouldRunSuiteWithIncludedMethods() { + // shouldRun method is null - method pattern test ??? TestListResolver resolver = new TestListResolver( "#*Fail*, %regex[#.*One], #testSuccessThree" ); assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) ); } public void testShouldRunAny() { - TestListResolver resolver = TestListResolver.getEmptyTestListResolver(); + TestListResolver resolver = new TestListResolver( "" ); assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) ); resolver = new TestListResolver( Collections.emptySet() ); @@ -267,13 +270,16 @@ public void testShouldRunAny() public void testClassFilter() { TestListResolver resolver = new TestListResolver( "#test" ); - assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) ); + assertTrue( resolver.shouldRun( "pkg/MyTest.class", "test" ) ); resolver = new TestListResolver( "!#test" ); - assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) ); + assertFalse( resolver.shouldRun( "pkg/MyTest.class", "test" ) ); resolver = new TestListResolver( "SomeOtherClass" ); assertFalse( resolver.shouldRun( "pkg/MyTest.class", null ) ); + + resolver = new TestListResolver( "MyTest" ); + assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) ); } public void testBrokenPatternThrowsException() @@ -365,7 +371,6 @@ public void testTestListResolverWithMethods() assertTrue( resolver.shouldRun( "BTest.class", null ) ); assertFalse( resolver.shouldRun( "BTest.class", "failedTest" ) ); assertTrue( resolver.shouldRun( "CTest.class", null ) ); - assertFalse( TestListResolver.optionallyWildcardFilter( resolver ).isEmpty() ); } private static Set toSet( ResolvedTest... patterns ) @@ -401,19 +406,6 @@ public void testInclusiveWithDefaultExclusivePattern() assertTrue( runnable ); } - public void testWildcard() - { - TestListResolver tlr = TestListResolver.optionallyWildcardFilter( new TestListResolver( (String) null ) ); - assertThat( tlr, is( new TestListResolver( "**/*.class" ) ) ); - assertThat( tlr.isWildcard(), is( true ) ); - assertThat( tlr.isEmpty(), is( false ) ); - - tlr = TestListResolver.optionallyWildcardFilter( new TestListResolver( "**/**/MethodLessPattern.class" ) ); - assertThat( tlr, is( new TestListResolver( "**/*.class" ) ) ); - assertThat( tlr.isWildcard(), is( true ) ); - assertThat( tlr.isEmpty(), is( false ) ); - } - public void testRegexRuleViolationQuotedHashMark() { try 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 a69d870078..61a646e557 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 @@ -933,8 +933,7 @@ public void testWithJUnitCoreFirstClassAndSingleMethod() @Test public void testShouldRunSuite() { - TestListResolver filter = new TestListResolver( "Su?te" ); - filter = TestListResolver.optionallyWildcardFilter( filter ); + TestListResolver filter = new TestListResolver( "*.class" ); JUnitCore core = new JUnitCore(); Result result = core.run( Request.classes( Suite.class ).filterWith( new MethodFilter( filter ) ) ); assertTrue( result.wasSuccessful() ); @@ -951,7 +950,6 @@ public void testShouldRunParameterized() + "PT#testC*, " + "!PT.java#testCY[?]," + "%regex[.*.tests.pt.PT.class#w.*|x.*T.*]" ); - filter = TestListResolver.optionallyWildcardFilter( filter ); JUnitCore core = new JUnitCore(); Result result = core.run( Request.classes( PT.class ).filterWith( new MethodFilter( filter ) ) ); assertTrue( result.wasSuccessful() ); @@ -970,7 +968,6 @@ public void testShouldRunParameterizedWithPlusDelimiter() // x12T35[0], x12T35[1] TestListResolver filter = new TestListResolver( "%regex[.*.PT.* # w.*|x(\\d+)T(\\d+)\\[(\\d+)\\]]" ); - filter = TestListResolver.optionallyWildcardFilter( filter ); JUnitCore core = new JUnitCore(); Result result = core.run( Request.classes( PT.class ).filterWith( new MethodFilter( filter ) ) ); assertTrue( result.wasSuccessful() ); diff --git a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java index 5c38caa70d..b62c5f4efe 100644 --- a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java +++ b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java @@ -67,7 +67,6 @@ import static org.apache.maven.surefire.common.junit4.Notifier.pureNotifier; import static org.apache.maven.surefire.api.report.ConsoleOutputCapture.startCapture; import static org.apache.maven.surefire.api.report.SimpleReportEntry.withException; -import static org.apache.maven.surefire.api.testset.TestListResolver.optionallyWildcardFilter; import static org.apache.maven.surefire.api.util.TestsToRun.fromClass; import static org.apache.maven.surefire.api.util.internal.ObjectUtils.systemProps; import static org.junit.runner.Request.aClass; @@ -274,14 +273,13 @@ private void executeWithRerun( Class clazz, Notifier notifier, RunModeSetter { JUnitTestFailureListener failureListener = new JUnitTestFailureListener(); notifier.addListener( failureListener ); - boolean hasMethodFilter = testResolver != null && testResolver.hasMethodPatterns(); try { try { notifier.asFailFast( isFailFast() ); - execute( clazz, notifier, hasMethodFilter ? createMethodFilter() : null ); + execute( clazz, notifier, createMethodFilter() ); } finally { @@ -432,7 +430,6 @@ private static boolean hasFilteredOutAllChildren( Description description ) private Filter createMethodFilter() { - TestListResolver methodFilter = optionallyWildcardFilter( testResolver ); - return methodFilter.isEmpty() || methodFilter.isWildcard() ? null : new TestResolverFilter( methodFilter ); + return testResolver != null && testResolver.hasMethodPatterns() ? new TestResolverFilter( testResolver ) : null; } } 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 7ed483426f..6143ab710d 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 @@ -49,7 +49,6 @@ import static org.apache.maven.surefire.api.report.ConsoleOutputCapture.startCapture; import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN; import static org.apache.maven.surefire.api.report.RunMode.RERUN_TEST_AFTER_FAILURE; -import static org.apache.maven.surefire.api.testset.TestListResolver.optionallyWildcardFilter; import static org.apache.maven.surefire.api.util.TestsToRun.fromClass; import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.generateFailingTestDescriptions; import static org.apache.maven.surefire.common.junit4.JUnit4RunListenerFactory.createCustomListeners; @@ -276,16 +275,14 @@ private Filter createJUnit48Filter() final FilterFactory factory = new FilterFactory( testClassLoader ); Map props = providerParameters.getProviderProperties(); Filter groupFilter = factory.canCreateGroupFilter( props ) ? factory.createGroupFilter( props ) : null; - TestListResolver methodFilter = optionallyWildcardFilter( testResolver ); - boolean onlyGroups = methodFilter.isEmpty() || methodFilter.isWildcard(); - if ( onlyGroups ) + if ( testResolver.hasMethodPatterns() ) { - return groupFilter; + Filter jUnitMethodFilter = factory.createMethodFilter( testResolver ); + return groupFilter == null ? jUnitMethodFilter : factory.and( groupFilter, jUnitMethodFilter ); } else { - Filter jUnitMethodFilter = factory.createMethodFilter( methodFilter ); - return groupFilter == null ? jUnitMethodFilter : factory.and( groupFilter, jUnitMethodFilter ); + return groupFilter; } } diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java index 0ca1403a83..3a88f962ea 100644 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java @@ -47,8 +47,6 @@ import static org.apache.maven.surefire.api.report.ConsoleOutputCapture.startCapture; import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN; -import static org.apache.maven.surefire.api.testset.TestListResolver.getEmptyTestListResolver; -import static org.apache.maven.surefire.api.testset.TestListResolver.optionallyWildcardFilter; import static org.apache.maven.surefire.api.util.TestsToRun.fromClass; /** @@ -205,7 +203,7 @@ public void update( Command command ) private TestNGDirectoryTestSuite newDirectorySuite() { return new TestNGDirectoryTestSuite( testRequest.getTestSourceDirectory().toString(), providerProperties, - reporterConfiguration.getReportsDirectory(), getTestFilter(), + reporterConfiguration.getReportsDirectory(), getTestMethodFilterFilter(), mainCliOptions, getSkipAfterFailureCount() ); } @@ -247,13 +245,13 @@ private TestsToRun scanClassPath() private boolean hasSpecificTests() { TestListResolver specificTestPatterns = testRequest.getTestListResolver(); - return !specificTestPatterns.isEmpty() && !specificTestPatterns.isWildcard(); + return !specificTestPatterns.isEmpty(); } - private TestListResolver getTestFilter() + private TestListResolver getTestMethodFilterFilter() { - TestListResolver filter = optionallyWildcardFilter( testRequest.getTestListResolver() ); - return filter.isWildcard() ? getEmptyTestListResolver() : filter; + TestListResolver filter = testRequest.getTestListResolver(); + return filter.hasMethodPatterns() ? filter : null; } // If we have access to IResultListener, return a ConfigurationAwareTestNGReporter.