Repository: maven-surefire Updated Branches: refs/heads/master bc1588546 -> 6c8bab59a
[SUREFIRE-995] Support searching superclass for JUnit @Category Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/6c8bab59 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/6c8bab59 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/6c8bab59 Branch: refs/heads/master Commit: 6c8bab59ab8908b13817052d514c02bc800b4db3 Parents: bc15885 Author: Tibor17 <tibo...@lycos.com> Authored: Mon Dec 15 00:38:40 2014 +0100 Committer: Tibor17 <tibo...@lycos.com> Committed: Mon Dec 15 00:38:40 2014 +0100 ---------------------------------------------------------------------- .../plugin/surefire/AbstractSurefireMojo.java | 10 +- .../src/site/apt/examples/junit.apt.vm | 4 + .../jiras/Surefire995CategoryInheritanceIT.java | 90 ++++++++++++++++++ .../surefire-995-categoryInheritance/pom.xml | 97 ++++++++++++++++++++ .../java/jiras/surefire955/CategorizedTest.java | 35 +++++++ .../java/jiras/surefire955/NotIncludedTest.java | 33 +++++++ .../java/jiras/surefire955/SomeCategory.java | 24 +++++ .../surefire955/SpecialCategorizedTest.java | 34 +++++++ .../surefire955/SpecialNonCategoryTest.java | 33 +++++++ .../surefire/common/junit48/FilterFactory.java | 2 +- 10 files changed, 359 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index bdfb553..dee273d 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -394,7 +394,10 @@ public abstract class AbstractSurefireMojo * (TestNG/JUnit47 provider with JUnit4.8+ only) Groups for this test. Only classes/methods/etc decorated with one * of the groups specified here will be included in test run, if specified.<br/> * For JUnit, this parameter forces the use of the 4.7 provider<br/> - * This parameter is ignored if the <code>suiteXmlFiles</code> parameter is specified. + * This parameter is ignored if the <code>suiteXmlFiles</code> parameter is specified.<br/> + * Since version 2.18.1 and JUnit 4.12, the <em>@Category<em> annotation type is automatically inherited from + * superclasses, see <em>@java.lang.annotation.Inherited</em>. Make sure that test class inheritance still makes + * sense together with <em>@Category<em> annotation of the JUnit 4.12 or higher appeared in superclass. * * @since 2.2 */ @@ -405,7 +408,10 @@ public abstract class AbstractSurefireMojo * (TestNG/JUnit47 provider with JUnit4.8+ only) Excluded groups. Any methods/classes/etc with one of the groups * specified in this list will specifically not be run.<br/> * For JUnit, this parameter forces the use of the 4.7 provider<br/> - * This parameter is ignored if the <code>suiteXmlFiles</code> parameter is specified. + * This parameter is ignored if the <code>suiteXmlFiles</code> parameter is specified.<br/> + * Since version 2.18.1 and JUnit 4.12, the <em>@Category<em> annotation type is automatically inherited from + * superclasses, see <em>@java.lang.annotation.Inherited</em>. Make sure that test class inheritance still makes + * sense together with <em>@Category<em> annotation of the JUnit 4.12 or higher appeared in superclass. * * @since 2.2 */ http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/maven-surefire-plugin/src/site/apt/examples/junit.apt.vm ---------------------------------------------------------------------- diff --git a/maven-surefire-plugin/src/site/apt/examples/junit.apt.vm b/maven-surefire-plugin/src/site/apt/examples/junit.apt.vm index 40d45b1..6473f16 100644 --- a/maven-surefire-plugin/src/site/apt/examples/junit.apt.vm +++ b/maven-surefire-plugin/src/site/apt/examples/junit.apt.vm @@ -276,3 +276,7 @@ else The <<<@Category>>> annotation can also be applied at class-level. For more information on JUnit, see the {{{http://www.junit.org}JUnit web site}}. + + Since version 2.18.1 and JUnit 4.12, the <<<@Category>>> annotation type is automatically inherited from + superclasses, see <<<@java.lang.annotation.Inherited>>>. Make sure that test class inheritance still makes sense + together with <<<@Category>>> annotation of the JUnit 4.12 or higher appeared in superclass. http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire995CategoryInheritanceIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire995CategoryInheritanceIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire995CategoryInheritanceIT.java new file mode 100644 index 0000000..2085d93 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire995CategoryInheritanceIT.java @@ -0,0 +1,90 @@ +package org.apache.maven.surefire.its.jiras; + +/* + * 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.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.apache.maven.surefire.its.fixture.SurefireLauncher; +import org.junit.Test; + +/** + * @author <a href="mailto:tibordig...@apache.org">Tibor Digana (tibor17)</a> + * @see {@linkplain https://jira.codehaus.org/browse/SUREFIRE-995} + * @since 2.18.1 + */ +public class Surefire995CategoryInheritanceIT + extends SurefireJUnit4IntegrationTestCase +{ + + @Test + public void negativeTestShouldRunAllCategories() + { + unpack() + .setTestToRun( "Special*Test" ) + .executeTest() + .verifyErrorFree( 3 ); + } + + @Test + public void junit411ShouldRunExplicitCategory() + { + unpack() + .addGoal( "-Ppositive-tests" ) + .sysProp( "version.junit", "4.11" ) + .executeTest() + .verifyErrorFree( 1 ) + .verifyTextInLog( "CategorizedTest#a" ); + } + + @Test + public void junit411ShouldExcludeExplicitCategory() + { + unpack() + .addGoal( "-Ppositive-tests-excluded-categories" ) + .sysProp( "version.junit", "4.11" ) + .executeTest() + .verifyErrorFree( 2 ); + } + + @Test + public void junit412ShouldRunInheritedCategory() + { + unpack() + .setTestToRun( "Special*Test" ) + .addGoal( "-Ppositive-tests" ) + .executeTest() + .verifyErrorFree( 2 ); + } + + @Test + public void junit412ShouldExcludeInheritedCategory() + { + unpack() + .setTestToRun( "Special*Test" ) + .addGoal( "-Ppositive-tests-excluded-categories" ) + .executeTest() + .verifyErrorFree( 1 ) + .verifyTextInLog( "SpecialNonCategoryTest#test" ); + } + + private SurefireLauncher unpack() + { + return unpack( "surefire-995-categoryInheritance" ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/pom.xml b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/pom.xml new file mode 100644 index 0000000..7245ccb --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/pom.xml @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>it-parent</artifactId> + <version>1.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>jiras-surefire-995</artifactId> + <version>1.0</version> + <url>http://maven.apache.org</url> + <properties> + <version.junit>4.12</version.junit> + </properties> + <developers> + <developer> + <id>tibordigana</id> + <name>Tibor DigaÅa (tibor17)</name> + <email>tibordig...@apache.org</email> + <roles> + <role>Committer</role> + </roles> + <timezone>Europe/Bratislava</timezone> + </developer> + </developers> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${version.junit}</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>positive-tests</id> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <groups>jiras.surefire955.SomeCategory</groups> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>positive-tests-excluded-categories</id> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <excludedGroups>jiras.surefire955.SomeCategory</excludedGroups> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/CategorizedTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/CategorizedTest.java b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/CategorizedTest.java new file mode 100644 index 0000000..a25b15a --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/CategorizedTest.java @@ -0,0 +1,35 @@ +package jiras.surefire955; + +/* + * 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; +import org.junit.experimental.categories.Category; + +@Category( SomeCategory.class ) +public class CategorizedTest +{ + + @Test + public void a() + { + System.out.println( "CategorizedTest#a" ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/NotIncludedTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/NotIncludedTest.java b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/NotIncludedTest.java new file mode 100644 index 0000000..c52bff0 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/NotIncludedTest.java @@ -0,0 +1,33 @@ +package jiras.surefire955; + +/* + * 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 NotIncludedTest +{ + + @Test + public void test() + { + System.out.println( "NotIncludedTest#test" ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SomeCategory.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SomeCategory.java b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SomeCategory.java new file mode 100644 index 0000000..d83b4ba --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SomeCategory.java @@ -0,0 +1,24 @@ +package jiras.surefire955; + +/* + * 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. + */ + +public interface SomeCategory +{ +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SpecialCategorizedTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SpecialCategorizedTest.java b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SpecialCategorizedTest.java new file mode 100644 index 0000000..8082f43 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SpecialCategorizedTest.java @@ -0,0 +1,34 @@ +package jiras.surefire955; + +/* + * 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 final class SpecialCategorizedTest + extends CategorizedTest +{ + + @Test + public void b() + { + System.out.println( "SpecialCategorizedTest#b" ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SpecialNonCategoryTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SpecialNonCategoryTest.java b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SpecialNonCategoryTest.java new file mode 100644 index 0000000..853ae50 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-995-categoryInheritance/src/test/java/jiras/surefire955/SpecialNonCategoryTest.java @@ -0,0 +1,33 @@ +package jiras.surefire955; + +/* + * 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 SpecialNonCategoryTest +{ + + @Test + public void test() + { + System.out.println( "SpecialNonCategoryTest#test" ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6c8bab59/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 97e404b..3d5e4c4 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 @@ -288,7 +288,7 @@ public class FilterFactory } } - cats.remove( null ); + cats.removeAll( Collections.<Class<?>>singleton( null ) ); boolean result = matcher.enabled( cats.toArray( new Class<?>[cats.size()] ) );