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..606824325c 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; @@ -257,7 +257,7 @@ public void testShouldRunSuiteWithIncludedMethods() public void testShouldRunAny() { - TestListResolver resolver = TestListResolver.getEmptyTestListResolver(); + TestListResolver resolver = new TestListResolver( "" ); assertTrue( resolver.shouldRun( "pkg/MyTest.class", null ) ); resolver = new TestListResolver( Collections.emptySet() ); @@ -365,7 +365,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 +400,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-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java index ad2ec944d2..1d22607811 100644 --- a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java +++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java @@ -32,7 +32,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.shared.utils.StringUtils.isBlank; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; @@ -56,6 +55,7 @@ import org.apache.maven.surefire.api.report.ReporterException; import org.apache.maven.surefire.api.report.ReporterFactory; import org.apache.maven.surefire.api.suite.RunResult; +import org.apache.maven.surefire.api.testset.TestListResolver; import org.apache.maven.surefire.api.testset.TestSetFailedException; import org.apache.maven.surefire.api.util.ScanResult; import org.apache.maven.surefire.api.util.SurefireReflectionException; @@ -275,11 +275,11 @@ private Filter[] newFilters() .map( TagFilter::excludeTags ) .ifPresent( filters::add ); - of( optionallyWildcardFilter( parameters.getTestRequest().getTestListResolver() ) ) - .filter( f -> !f.isEmpty() ) - .filter( f -> !f.isWildcard() ) - .map( TestMethodFilter::new ) - .ifPresent( filters::add ); + TestListResolver resolver = parameters.getTestRequest().getTestListResolver(); + if ( resolver.hasMethodPatterns() ) + { + filters.add( new TestMethodFilter( resolver ) ); + } getPropertiesList( INCLUDE_JUNIT5_ENGINES_PROP ) .map( EngineFilter::includeEngines ) diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTest.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTest.java index f734bab115..9903ab2068 100644 --- a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTest.java +++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTest.java @@ -899,7 +899,6 @@ public void shouldFilterTestMethod() ProviderParameters providerParameters = providerParametersMock(); TestListResolver testListResolver = new TestListResolver( "**/*Test#test*" ); assertFalse( testListResolver.isEmpty() ); - assertFalse( testListResolver.isWildcard() ); TestRequest request = new TestRequest( null, null, testListResolver, 0 ); when( providerParameters.getTestRequest() ).thenReturn( request ); @@ -926,7 +925,6 @@ public void shouldNotFilterEmpty() ProviderParameters providerParameters = providerParametersMock(); TestListResolver testListResolver = new TestListResolver( "" ); assertTrue( testListResolver.isEmpty() ); - assertFalse( testListResolver.isWildcard() ); TestRequest request = new TestRequest( null, null, testListResolver, 0 ); when( providerParameters.getTestRequest() ).thenReturn( request ); @@ -941,7 +939,6 @@ public void shouldNotFilterWildcard() { ProviderParameters providerParameters = providerParametersMock(); TestListResolver testListResolver = new TestListResolver( "*.java" ); - assertTrue( testListResolver.isWildcard() ); assertFalse( testListResolver.isEmpty() ); TestRequest request = new TestRequest( null, null, testListResolver, 0 ); when( providerParameters.getTestRequest() ).thenReturn( request ); 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.