http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestFour.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestFour.java b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestFour.java new file mode 100644 index 0000000..824b0d5 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestFour.java @@ -0,0 +1,49 @@ +package jiras.surefire745; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + + +public class TestFour +{ + @Rule + public final TestName testName = new TestName(); + + @Test + public void testSuccessOne() + { + System.out.println( getClass() + "#" + testName.getMethodName() ); + } + + @Test + public void testSuccessTwo() + { + System.out.println( getClass() + "#" + testName.getMethodName() ); + } + + @Test + public void testSuccessThree() + { + System.out.println( getClass() + "#" + testName.getMethodName() ); + } +}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestThree.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestThree.java b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestThree.java new file mode 100644 index 0000000..a868e7c --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestThree.java @@ -0,0 +1,51 @@ +package jiras.surefire745; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +import static org.junit.Assert.*; + +public class TestThree +{ + @Rule + public final TestName testName = new TestName(); + + @Test + public void testSuccessOne() + { + System.out.println( getClass() + "#" + testName.getMethodName() ); + } + + @Test + public void testSuccessTwo() + { + System.out.println( getClass() + "#" + testName.getMethodName() ); + } + + @Test + public void testFailOne() + { + System.out.println( getClass() + "#" + testName.getMethodName() ); + fail(); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestTwo.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestTwo.java b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestTwo.java new file mode 100644 index 0000000..5f1182d --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/jiras/surefire745/TestTwo.java @@ -0,0 +1,42 @@ +package jiras.surefire745; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class TestTwo +{ + @Rule + public final TestName testName = new TestName(); + + @Test + public void testSuccessOne() + { + System.out.println( getClass() + "#" + testName.getMethodName() ); + } + + @Test + public void testSuccessTwo() + { + System.out.println( getClass() + "#" + testName.getMethodName() ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/BasicTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/BasicTest.java b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/BasicTest.java deleted file mode 100644 index d7921e0..0000000 --- a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/BasicTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package junit4; - - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.junit.Assert; -import org.junit.Test; - - -public class BasicTest -{ - - @Test - public void testSuccessOne() - { - } - - @Test - public void testSuccessTwo() - { - } - - @Test - public void testFailOne() - { - Assert.fail( ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestFive.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestFive.java b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestFive.java deleted file mode 100644 index 642a5ad..0000000 --- a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestFive.java +++ /dev/null @@ -1,43 +0,0 @@ -package junit4; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.junit.Test; - - -public class TestFive -{ - - @Test - public void testSuccessOne() - { - } - - @Test - public void testSuccessTwo() - { - } - - @Test - public void testSuccessThree() - { - } - -} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestFour.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestFour.java b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestFour.java deleted file mode 100644 index f8acce9..0000000 --- a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestFour.java +++ /dev/null @@ -1,43 +0,0 @@ -package junit4; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.junit.Test; - - -public class TestFour -{ - - @Test - public void testSuccessOne() - { - } - - @Test - public void testSuccessTwo() - { - } - - @Test - public void testSuccessThree() - { - } - -} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestThree.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestThree.java b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestThree.java deleted file mode 100644 index 7d31dfb..0000000 --- a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestThree.java +++ /dev/null @@ -1,45 +0,0 @@ -package junit4; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.junit.Assert; -import org.junit.Test; - - -public class TestThree -{ - - @Test - public void testSuccessOne() - { - } - - @Test - public void testSuccessTwo() - { - } - - @Test - public void testFailOne() - { - Assert.fail(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestTwo.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestTwo.java b/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestTwo.java deleted file mode 100644 index e8648d2..0000000 --- a/surefire-integration-tests/src/test/resources/junit48-multiple-method-patterns/src/test/java/junit4/TestTwo.java +++ /dev/null @@ -1,41 +0,0 @@ -package junit4; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.junit.Assert; -import org.junit.Test; - - -public class TestTwo -{ - - @Test - public void testSuccessOne() - { - Assert.assertTrue( true ); - } - - @Test - public void testSuccessTwo() - { - Assert.assertTrue( true ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java index b5964a8..fb625a2 100644 --- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java +++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java @@ -218,6 +218,6 @@ public class JUnit4RunListener public static boolean isFailureInsideJUnitItself( Failure failure ) { - return failure.getDescription().getDisplayName().equals( "Test mechanism" ); + return Description.TEST_MECHANISM.equals( failure.getDescription() ); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java new file mode 100644 index 0000000..4368434 --- /dev/null +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/AndFilter.java @@ -0,0 +1,62 @@ +package org.apache.maven.surefire.common.junit48; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; + +final class AndFilter + extends Filter +{ + private final Filter[] filters; + + AndFilter( Filter... filters ) + { + this.filters = filters; + } + + @Override + public boolean shouldRun( Description description ) + { + for ( Filter filter : filters ) + { + if ( !filter.shouldRun( description ) ) + { + return false; + } + } + return true; + } + + @Override + public String describe() + { + String description = ""; + for ( int i = 0; i < filters.length; i++ ) + { + description += filters[i].describe(); + if ( i != filters.length - 1 ) + { + description += " AND "; + } + } + return description; + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/CombinedCategoryFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/CombinedCategoryFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/CombinedCategoryFilter.java new file mode 100644 index 0000000..9cd2131 --- /dev/null +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/CombinedCategoryFilter.java @@ -0,0 +1,99 @@ +package org.apache.maven.surefire.common.junit48; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; + +import java.util.Collection; + +final class CombinedCategoryFilter + extends Filter +{ + private final Collection<Filter> includedFilters; + + private final Collection<Filter> excludedFilters; + + CombinedCategoryFilter( Collection<Filter> includedFilters, Collection<Filter> excludedFilters ) + { + this.includedFilters = includedFilters; + this.excludedFilters = excludedFilters; + } + + @Override + public boolean shouldRun( Description description ) + { + return ( includedFilters.isEmpty() || inOneOfFilters( includedFilters, description ) ) + && ( excludedFilters.isEmpty() || !inOneOfFilters( excludedFilters, description ) ); + } + + private boolean inOneOfFilters( Collection<Filter> filters, Description description ) + { + for ( Filter f : filters ) + { + if ( f.shouldRun( description ) ) + { + return true; + } + } + return false; + } + + @Override + public String describe() + { + StringBuilder sb = new StringBuilder(); + if ( !includedFilters.isEmpty() ) + { + sb.append( "(" ); + sb.append( joinFilters( includedFilters, " OR " ) ); + sb.append( ")" ); + if ( !excludedFilters.isEmpty() ) + { + sb.append( " AND " ); + } + } + + if ( !excludedFilters.isEmpty() ) + { + sb.append( "NOT (" ); + sb.append( joinFilters( includedFilters, " OR " ) ); + sb.append( ")" ); + } + + return sb.toString(); + } + + private String joinFilters( Collection<Filter> filters, String sep ) + { + boolean isFirst = true; + StringBuilder sb = new StringBuilder(); + for ( Filter f : filters ) + { + if ( !isFirst ) + { + sb.append( sep ); + } + sb.append( f.describe() ); + isFirst = false; + } + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FailingMethodFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FailingMethodFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FailingMethodFilter.java new file mode 100644 index 0000000..da9cfd6 --- /dev/null +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FailingMethodFilter.java @@ -0,0 +1,71 @@ +package org.apache.maven.surefire.common.junit48; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; + +import java.util.Map; +import java.util.Set; + +/** + * Only run test methods in the given input map, indexed by test class + */ +final class FailingMethodFilter + extends Filter +{ + // Map from Class -> List of method names. Are the method names hashed to include the signature? + private final Map<Class<?>, Set<String>> failingClassMethodMap; + + public FailingMethodFilter( Map<Class<?>, Set<String>> failingClassMethodMap ) + { + this.failingClassMethodMap = failingClassMethodMap; + } + + @Override + public boolean shouldRun( Description description ) + { + return isDescriptionMatch( description ); + } + + private boolean isDescriptionMatch( Description description ) + { + if ( description.getTestClass() == null || description.getMethodName() == null ) + { + for ( Description childrenDescription : description.getChildren() ) + { + if ( isDescriptionMatch( childrenDescription ) ) + { + return true; + } + } + return false; + } + + Set<String> testMethods = failingClassMethodMap.get( description.getTestClass() ); + return testMethods != null && testMethods.contains( description.getMethodName() ); + } + + @Override + public String describe() + { + return "By failing class method"; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/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 3f81f87..4bdd438 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 @@ -19,23 +19,13 @@ package org.apache.maven.surefire.common.junit48; * under the License. */ -import org.apache.maven.shared.utils.StringUtils; -import org.apache.maven.shared.utils.io.SelectorUtils; import org.apache.maven.surefire.booter.ProviderParameterNames; -import org.apache.maven.surefire.group.match.AndGroupMatcher; import org.apache.maven.surefire.group.match.GroupMatcher; -import org.apache.maven.surefire.group.match.InverseGroupMatcher; import org.apache.maven.surefire.group.parse.GroupMatcherParser; import org.apache.maven.surefire.group.parse.ParseException; -import org.junit.experimental.categories.Category; -import org.junit.runner.Description; +import org.apache.maven.surefire.testset.TestListResolver; import org.junit.runner.manipulation.Filter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -66,8 +56,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 ); } } @@ -80,8 +70,8 @@ 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 ); } } @@ -103,6 +93,11 @@ public class FilterFactory return new MethodFilter( requestedTestMethod ); } + public Filter createMethodFilter( TestListResolver resolver ) + { + return new MethodFilter( resolver ); + } + public Filter createFailingMethodFilter( Map<Class<?>, Set<String>> failingClassMethodMap ) { return new FailingMethodFilter( failingClassMethodMap ); @@ -112,396 +107,4 @@ public class FilterFactory { return new AndFilter( filter1, filter2 ); } - - private static class MethodFilter - extends Filter - { - - private static class RequestedTestMethod - { - final String classPattern; - final String methodPattern; - - private RequestedTestMethod( String className, String 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 String convertToPath( String className ) - { - return className.replace( '.', '/' ); - } - - public boolean isDescriptionmatch( Description description ) - { - String describedClassName = description.getClassName(); - String describedMethodName = description.getMethodName(); - - if ( methodPattern != null ) - { - if ( describedMethodName == null || !SelectorUtils.match( methodPattern, describedMethodName ) ) - { - return false; - } - } - - if ( classPattern != null && describedClassName != null ) - { - String describedPath = convertToPath( describedClassName ); - return SelectorUtils.matchPath( classPattern, describedPath ); - } - - return true; - - } - } - - private final String requestString; - private final Collection<RequestedTestMethod> requestedTestMethods; - - public MethodFilter( String requestString ) - { - Collection<RequestedTestMethod> requestedTestMethods = new ArrayList<RequestedTestMethod>(); - - if ( !requestString.contains( "#" ) ) - { - // 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 - { - // possibly several classes and methods separated by comma - // several methods in the same class separated by plus - - for ( String request : StringUtils.split( requestString, "," ) ) - { - int index = request.indexOf( '#' ); - if ( index < 0 ) - { - // request can also contain complete classes - requestedTestMethods.add( new RequestedTestMethod( request, null ) ); - } - else - { - String className = index == 0 ? null : request.substring( 0, index ); - String methodNames = request.substring( index + 1 ); - for ( String methodName : StringUtils.split( methodNames, "+" ) ) - { - requestedTestMethods.add( new RequestedTestMethod( className, methodName ) ); - } - } - } - } - - this.requestString = requestString; - this.requestedTestMethods = requestedTestMethods; - } - - @Override - public boolean shouldRun( Description description ) - { - for ( Description o : description.getChildren() ) - { - if ( isDescriptionMatch( o ) || shouldRun( o ) ) - { - return true; - } - - } - return isDescriptionMatch( description ); - } - - private boolean isDescriptionMatch( Description description ) - { - for ( RequestedTestMethod requestedTestMethod : requestedTestMethods ) - { - if ( requestedTestMethod.isDescriptionmatch( description ) ) - { - return true; - } - } - return false; - } - - @Override - public String describe() - { - return "By method " + requestString; - } - } - - // Only run test methods in the given input map, indexed by test class - private static class FailingMethodFilter - extends Filter - { - // Map from Class -> List of method names. Are the method names hashed to include the signature? - private final Map<Class<?>, Set<String>> failingClassMethodMap; - - public FailingMethodFilter( Map<Class<?>, Set<String>> failingClassMethodMap ) - { - this.failingClassMethodMap = failingClassMethodMap; - } - - @Override - public boolean shouldRun( Description description ) - { - return isDescriptionMatch( description ); - } - - private boolean isDescriptionMatch( Description description ) - { - if ( description.getTestClass() == null || description.getMethodName() == null ) - { - for ( Description childrenDescription : description.getChildren() ) - { - if ( isDescriptionMatch( childrenDescription ) ) - { - return true; - } - } - return false; - } - - Set<String> testMethods = failingClassMethodMap.get( description.getTestClass() ); - return testMethods != null && testMethods.contains( description.getMethodName() ); - } - - @Override - public String describe() - { - return "By failing class method"; - } - } - - private static class GroupMatcherCategoryFilter - extends Filter - { - - private final AndGroupMatcher matcher; - - public GroupMatcherCategoryFilter( GroupMatcher included, GroupMatcher excluded ) - { - GroupMatcher invertedExclude = excluded == null ? null : new InverseGroupMatcher( excluded ); - if ( included != null || invertedExclude != null ) - { - matcher = new AndGroupMatcher(); - if ( included != null ) - { - matcher.addMatcher( included ); - } - - if ( invertedExclude != null ) - { - matcher.addMatcher( invertedExclude ); - } - } - else - { - matcher = null; - } - } - - @Override - public boolean shouldRun( Description description ) - { - if ( description.getMethodName() == null || description.getTestClass() == null ) - { - return shouldRun( description, null, null ); - } - else - { - return shouldRun( description, Description.createSuiteDescription( description.getTestClass() ), - description.getTestClass() ); - } - } - - private static void findSuperclassCategories( Set<Class<?>> cats, Class<?> clazz ) - { - if ( clazz != null && clazz.getSuperclass() != null ) - { - Category cat = clazz.getSuperclass().getAnnotation( Category.class ); - if ( cat != null ) - { - Collections.addAll( cats, cat.value() ); - } - else - { - findSuperclassCategories( cats, clazz.getSuperclass() ); - } - } - } - - private boolean shouldRun( Description description, Description parent, Class<?> parentClass ) - { - if ( matcher == null ) - { - return true; - } - else - { - Set<Class<?>> cats = new HashSet<Class<?>>(); - Category cat = description.getAnnotation( Category.class ); - if ( cat != null ) - { - Collections.addAll( cats, cat.value() ); - } - - if ( parent != null ) - { - cat = parent.getAnnotation( Category.class ); - if ( cat != null ) - { - Collections.addAll( cats, cat.value() ); - } - } - - if ( parentClass != null ) - { - findSuperclassCategories( cats, parentClass ); - } - - Class<?> testClass = description.getTestClass(); - if ( testClass != null ) - { - cat = testClass.getAnnotation( Category.class ); - if ( cat != null ) - { - Collections.addAll( cats, cat.value() ); - } - } - - cats.remove( null ); - - boolean result = matcher.enabled( cats.toArray( new Class<?>[cats.size()] ) ); - - if ( !result ) - { - ArrayList<Description> children = description.getChildren(); - if ( children != null ) - { - for ( Description child : children ) - { - if ( shouldRun( child, description, null ) ) - { - result = true; - break; - } - } - } - } - - return result; - } - } - - @Override - public String describe() - { - return matcher == null ? "ANY" : matcher.toString(); - } - } - - 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 - extends Filter - { - private final List<Filter> includedFilters; - - private final List<Filter> excludedFilters; - - public CombinedCategoryFilter( List<Filter> includedFilters, List<Filter> excludedFilters ) - { - this.includedFilters = includedFilters; - this.excludedFilters = excludedFilters; - } - - @Override - public boolean shouldRun( Description description ) - { - return ( includedFilters.isEmpty() || inOneOfFilters( includedFilters, description ) ) - && ( excludedFilters.isEmpty() || !inOneOfFilters( excludedFilters, description ) ); - } - - private boolean inOneOfFilters( List<Filter> filters, Description description ) - { - for ( Filter f : filters ) - { - if ( f.shouldRun( description ) ) - { - return true; - } - } - return false; - } - - @Override - public String describe() - { - StringBuilder sb = new StringBuilder(); - if ( !includedFilters.isEmpty() ) - { - sb.append( "(" ); - sb.append( joinFilters( includedFilters, " OR " ) ); - sb.append( ")" ); - if ( !excludedFilters.isEmpty() ) - { - sb.append( " AND " ); - } - } - if ( !excludedFilters.isEmpty() ) - { - sb.append( "NOT (" ); - sb.append( joinFilters( includedFilters, " OR " ) ); - sb.append( ")" ); - } - - return sb.toString(); - } - - private String joinFilters( List<Filter> filters, String sep ) - { - boolean isFirst = true; - StringBuilder sb = new StringBuilder(); - for ( Filter f : filters ) - { - if ( !isFirst ) - { - sb.append( sep ); - } - sb.append( f.describe() ); - isFirst = false; - } - return sb.toString(); - } - } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java new file mode 100644 index 0000000..6eeae93 --- /dev/null +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java @@ -0,0 +1,160 @@ +package org.apache.maven.surefire.common.junit48; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.surefire.group.match.AndGroupMatcher; +import org.apache.maven.surefire.group.match.GroupMatcher; +import org.apache.maven.surefire.group.match.InverseGroupMatcher; +import org.junit.experimental.categories.Category; +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +final class GroupMatcherCategoryFilter + extends Filter +{ + + private final AndGroupMatcher matcher; + + GroupMatcherCategoryFilter( GroupMatcher included, GroupMatcher excluded ) + { + GroupMatcher invertedExclude = excluded == null ? null : new InverseGroupMatcher( excluded ); + if ( included != null || invertedExclude != null ) + { + matcher = new AndGroupMatcher(); + if ( included != null ) + { + matcher.addMatcher( included ); + } + + if ( invertedExclude != null ) + { + matcher.addMatcher( invertedExclude ); + } + } + else + { + matcher = null; + } + } + + @Override + public boolean shouldRun( Description description ) + { + if ( description.getMethodName() == null || description.getTestClass() == null ) + { + return shouldRun( description, null, null ); + } + else + { + return shouldRun( description, Description.createSuiteDescription( description.getTestClass() ), + description.getTestClass() ); + } + } + + private static void findSuperclassCategories( Set<Class<?>> cats, Class<?> clazz ) + { + if ( clazz != null && clazz.getSuperclass() != null ) + { + Category cat = clazz.getSuperclass().getAnnotation( Category.class ); + if ( cat != null ) + { + Collections.addAll( cats, cat.value() ); + } + else + { + findSuperclassCategories( cats, clazz.getSuperclass() ); + } + } + } + + private boolean shouldRun( Description description, Description parent, Class<?> parentClass ) + { + if ( matcher == null ) + { + return true; + } + else + { + Set<Class<?>> cats = new HashSet<Class<?>>(); + Category cat = description.getAnnotation( Category.class ); + if ( cat != null ) + { + Collections.addAll( cats, cat.value() ); + } + + if ( parent != null ) + { + cat = parent.getAnnotation( Category.class ); + if ( cat != null ) + { + Collections.addAll( cats, cat.value() ); + } + } + + if ( parentClass != null ) + { + findSuperclassCategories( cats, parentClass ); + } + + Class<?> testClass = description.getTestClass(); + if ( testClass != null ) + { + cat = testClass.getAnnotation( Category.class ); + if ( cat != null ) + { + Collections.addAll( cats, cat.value() ); + } + } + + cats.remove( null ); + + boolean result = matcher.enabled( cats.toArray( new Class<?>[cats.size()] ) ); + + if ( !result ) + { + ArrayList<Description> children = description.getChildren(); + if ( children != null ) + { + for ( Description child : children ) + { + if ( shouldRun( child, description, null ) ) + { + result = true; + break; + } + } + } + } + + return result; + } + } + + @Override + public String describe() + { + return matcher == null ? "ANY" : matcher.toString(); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/InvertedFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/InvertedFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/InvertedFilter.java new file mode 100644 index 0000000..1ce0b3c --- /dev/null +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/InvertedFilter.java @@ -0,0 +1,46 @@ +package org.apache.maven.surefire.common.junit48; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; + +final class InvertedFilter + extends Filter +{ + private final Filter filter; + + InvertedFilter( Filter filter ) + { + this.filter = filter; + } + + @Override + public boolean shouldRun( Description description ) + { + return !filter.shouldRun( description ); + } + + @Override + public String describe() + { + return filter.describe(); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/MethodFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/MethodFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/MethodFilter.java new file mode 100644 index 0000000..61d08ce --- /dev/null +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/MethodFilter.java @@ -0,0 +1,89 @@ +package org.apache.maven.surefire.common.junit48; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.surefire.testset.ResolvedTest; +import org.apache.maven.surefire.testset.TestListResolver; +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; + +import java.util.Collection; +import java.util.LinkedHashSet; + +final class MethodFilter + extends Filter +{ + private final CombinedCategoryFilter combinedFilter; + + MethodFilter( String requestString ) + { + this( new TestListResolver( requestString ) ); + } + + MethodFilter( TestListResolver testResolver ) + { + Collection<Filter> includedFilters = new LinkedHashSet<Filter>(); + Collection<Filter> excludedFilters = new LinkedHashSet<Filter>(); + for ( ResolvedTest test : testResolver.getIncludedFilters() ) + { + includedFilters.add( new RequestedTest( test ) ); + } + for ( ResolvedTest test : testResolver.getExcludedFilters() ) + { + excludedFilters.add( new RequestedTest( test ) ); + } + combinedFilter = new CombinedCategoryFilter( includedFilters, excludedFilters ); + } + + @Override + public boolean shouldRun( Description description ) + { + if ( description.isEmpty() ) + { + return false; + } + else if ( description.isTest() ) + { + return combinedFilter.shouldRun( description ); + } + else if ( combinedFilter.shouldRun( description ) ) + { + //pribudlo - daj do JUnit4Provider + return true; + } + else + { + for ( Description o : description.getChildren() ) + { + if ( combinedFilter.shouldRun( o ) || shouldRun( o ) ) + { + return true; + } + } + return false; + } + } + + @Override + public String describe() + { + return combinedFilter.describe(); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java new file mode 100644 index 0000000..b5b2b56 --- /dev/null +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/OrFilter.java @@ -0,0 +1,62 @@ +package org.apache.maven.surefire.common.junit48; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; + +final class OrFilter + extends Filter +{ + private final Filter[] filters; + + OrFilter( Filter[] filters ) + { + this.filters = filters; + } + + @Override + public boolean shouldRun( Description description ) + { + for ( Filter filter : filters ) + { + if ( filter.shouldRun( description ) ) + { + return true; + } + } + return false; + } + + @Override + public String describe() + { + String description = ""; + for ( int i = 0; i < filters.length; i++ ) + { + description += filters[i].describe(); + if ( i != filters.length - 1 ) + { + description += " OR "; + } + } + return description; + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/889caca8/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java new file mode 100644 index 0000000..3862ff0 --- /dev/null +++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/RequestedTest.java @@ -0,0 +1,68 @@ +package org.apache.maven.surefire.common.junit48; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.surefire.testset.ResolvedTest; +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filter; + +final class RequestedTest + extends Filter +{ + private final ResolvedTest test; + + RequestedTest( ResolvedTest test ) + { + this.test = test; + } + + @Override + public boolean shouldRun( Description description ) + { + Class<?> realTestClass = description.getTestClass(); + String methodName = description.getMethodName(); + return realTestClass == null && methodName == null || test.shouldRun( realTestClass, methodName ); + } + + @Override + public String describe() + { + final String classPattern = test.getTestClassPattern(); + final String methodPattern = test.getTestMethodPattern(); + String description = classPattern == null ? "" : classPattern; + if ( methodPattern != null ) + { + description += "#" + methodPattern; + } + return description.length() == 0 ? "*" : description; + } + + @Override + public boolean equals( Object o ) + { + return this == o || o != null && getClass() == o.getClass() && test.equals( ( (RequestedTest) o ).test ); + } + + @Override + public int hashCode() + { + return test.hashCode(); + } +}