You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2013/04/12 20:07:17 UTC
git commit: [SUREFIRE-985] remove local cache in
GroupMatcherCategoryFilter
Updated Branches:
refs/heads/master a883a3afc -> 199c61625
[SUREFIRE-985] remove local cache in GroupMatcherCategoryFilter
The Description provided by some JUnit runners (such as Parameterized) may not contain enough information in order to be unique.
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/199c6162
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/199c6162
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/199c6162
Branch: refs/heads/master
Commit: 199c6162596b19d5b6e25cc0c3706bd657d92b1e
Parents: a883a3a
Author: Andreas Gudian <ag...@apache.org>
Authored: Fri Apr 12 20:06:48 2013 +0200
Committer: Andreas Gudian <ag...@apache.org>
Committed: Fri Apr 12 20:06:48 2013 +0200
----------------------------------------------------------------------
...efire985ParameterizedRunnerAndCategoriesIT.java | 68 ++++++++++++++
.../pom.xml | 55 +++++++++++
.../src/test/java/sample/CategoryActivated.java | 6 ++
.../src/test/java/sample/CategoryNotSelected.java | 6 ++
.../sample/parameterized/Parameterized01Test.java | 42 +++++++++
.../sample/parameterized/Parameterized02Test.java | 42 +++++++++
.../sample/parameterized/Parameterized03Test.java | 42 +++++++++
.../surefire/common/junit48/FilterFactory.java | 70 +--------------
8 files changed, 264 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/199c6162/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire985ParameterizedRunnerAndCategoriesIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire985ParameterizedRunnerAndCategoriesIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire985ParameterizedRunnerAndCategoriesIT.java
new file mode 100644
index 0000000..b86b291
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire985ParameterizedRunnerAndCategoriesIT.java
@@ -0,0 +1,68 @@
+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 java.io.FileNotFoundException;
+
+import org.apache.maven.shared.utils.xml.Xpp3Dom;
+import org.apache.maven.shared.utils.xml.Xpp3DomBuilder;
+import org.apache.maven.surefire.its.fixture.OutputValidator;
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.TestFile;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class Surefire985ParameterizedRunnerAndCategoriesIT
+ extends SurefireJUnit4IntegrationTestCase
+{
+
+ @Test
+ public void test()
+ throws Exception
+ {
+ OutputValidator validator = unpack( "surefire-985-parameterized-and-categories" ).maven().executeTest();
+ validator.assertTestSuiteResults( 12, 0, 0, 0 );
+
+ assertFalse( validator.getSurefireReportsXmlFile( "TEST-sample.parameterized.Parameterized01Test.xml" ).exists() );
+
+ TestFile reportFile2 =
+ validator.getSurefireReportsXmlFile( "TEST-sample.parameterized.Parameterized02Test.xml" );
+ assertTestCount( reportFile2, 4 );
+
+ TestFile reportFile3 =
+ validator.getSurefireReportsXmlFile( "TEST-sample.parameterized.Parameterized03Test.xml" );
+ assertTestCount( reportFile3, 8 );
+
+ }
+
+ private void assertTestCount( TestFile reportFile, int tests )
+ throws FileNotFoundException
+ {
+ assertTrue( reportFile.exists() );
+
+ Xpp3Dom testResult = Xpp3DomBuilder.build( reportFile.getFileInputStream(), "UTF-8" );
+ Xpp3Dom[] children = testResult.getChildren( "testcase" );
+ assertEquals( tests, children.length );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/199c6162/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/pom.xml b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/pom.xml
new file mode 100644
index 0000000..71d26cd
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/pom.xml
@@ -0,0 +1,55 @@
+<?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>
+ </parent>
+
+ <artifactId>surefire-985</artifactId>
+ <name>Tests Parameterized runner together with @Categories</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire.version}</version>
+ <configuration>
+ <runOrder>alphabetical</runOrder>
+ <groups>sample.CategoryActivated</groups>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/199c6162/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/CategoryActivated.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/CategoryActivated.java b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/CategoryActivated.java
new file mode 100644
index 0000000..14603e5
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/CategoryActivated.java
@@ -0,0 +1,6 @@
+package sample;
+
+public interface CategoryActivated
+{
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/199c6162/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/CategoryNotSelected.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/CategoryNotSelected.java b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/CategoryNotSelected.java
new file mode 100644
index 0000000..bcaad5f
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/CategoryNotSelected.java
@@ -0,0 +1,6 @@
+package sample;
+
+public interface CategoryNotSelected
+{
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/199c6162/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized01Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized01Test.java b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized01Test.java
new file mode 100644
index 0000000..7c34e95
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized01Test.java
@@ -0,0 +1,42 @@
+package sample.parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import sample.CategoryNotSelected;
+
+@RunWith( Parameterized.class )
+@Category( CategoryNotSelected.class )
+public class Parameterized01Test
+{
+ static
+ {
+ System.out.println( "Initializing Parameterized01Test" );
+ }
+
+ @Parameters
+ public static Collection<Integer[]> getParams()
+ {
+ return Arrays.asList( new Integer[] { 1 }, new Integer[] { 2 }, new Integer[] { 3 }, new Integer[] { 4 } );
+ }
+
+ public Parameterized01Test( Integer param )
+ {
+ }
+
+ @Test
+ public void testNothing()
+ {
+ }
+
+ @Test
+ public void testNothingEither()
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/199c6162/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized02Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized02Test.java b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized02Test.java
new file mode 100644
index 0000000..f1b3ff5
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized02Test.java
@@ -0,0 +1,42 @@
+package sample.parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import sample.CategoryActivated;
+
+@RunWith( Parameterized.class )
+public class Parameterized02Test
+{
+ static
+ {
+ System.out.println( "Initializing Parameterized02Test" );
+ }
+
+ @Parameters
+ public static Collection<Integer[]> getParams()
+ {
+ return Arrays.asList( new Integer[] { 1 }, new Integer[] { 2 }, new Integer[] { 3 }, new Integer[] { 4 } );
+ }
+
+ public Parameterized02Test( Integer param )
+ {
+ }
+
+ @Test
+ @Category( CategoryActivated.class )
+ public void testNothing()
+ {
+ }
+
+ @Test
+ public void testNothingEither()
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/199c6162/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized03Test.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized03Test.java b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized03Test.java
new file mode 100644
index 0000000..7aa9bc6
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-985-parameterized-and-categories/src/test/java/sample/parameterized/Parameterized03Test.java
@@ -0,0 +1,42 @@
+package sample.parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import sample.CategoryActivated;
+
+@Category( CategoryActivated.class )
+@RunWith( Parameterized.class )
+public class Parameterized03Test
+{
+ static
+ {
+ System.out.println( "Initializing Parameterized03Test" );
+ }
+
+ @Parameters
+ public static Collection<Integer[]> getParams()
+ {
+ return Arrays.asList( new Integer[] { 1 }, new Integer[] { 2 }, new Integer[] { 3 }, new Integer[] { 4 } );
+ }
+
+ public Parameterized03Test( Integer param )
+ {
+ }
+
+ @Test
+ public void testNothing()
+ {
+ }
+
+ @Test
+ public void testNothingEither()
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/199c6162/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 ff30e18..d3c5b07 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
@@ -21,12 +21,11 @@ package org.apache.maven.surefire.common.junit48;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
import java.util.Set;
+
import org.apache.maven.shared.utils.io.SelectorUtils;
import org.apache.maven.surefire.booter.ProviderParameterNames;
import org.apache.maven.surefire.group.match.AndGroupMatcher;
@@ -34,7 +33,6 @@ 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.junit.runner.manipulation.Filter;
@@ -84,10 +82,6 @@ public class FilterFactory
}
}
- // GroupMatcher included = commaSeparatedListToFilters( groups );
- // GroupMatcher excluded = commaSeparatedListToFilters( excludedGroups
- // );
-
if ( included != null && testClassLoader != null )
{
included.loadGroupClasses( testClassLoader );
@@ -101,39 +95,6 @@ public class FilterFactory
return new GroupMatcherCategoryFilter( included, excluded );
}
- // private GroupMatcher commaSeparatedListToFilters( String str )
- // {
- // List<GroupMatcher> included = new ArrayList<GroupMatcher>();
- // if ( str != null )
- // {
- // for ( String group : str.split( "," ) )
- // {
- // group = group.trim();
- // if ( group == null || group.length() == 0)
- // {
- // continue;
- // }
- //
- // try
- // {
- // GroupMatcher matcher = new GroupMatcherParser( group ).parse();
- // included.add( matcher );
- // }
- // catch ( ParseException e )
- // {
- // throw new IllegalArgumentException( "Invalid group expression: '" + group
- // + "'. Reason: "
- // + e.getMessage(), e );
- // }
- //
- // // Class<?> categoryType = classloadCategory( group );
- // // included.add( Categories.CategoryFilter.include( categoryType ) );
- // }
- // }
- //
- // return included.isEmpty() ? null : new OrGroupMatcher( included );
- // }
-
public Filter createMethodFilter( String requestedTestMethod )
{
return new MethodFilter( requestedTestMethod );
@@ -187,8 +148,6 @@ public class FilterFactory
private AndGroupMatcher matcher;
- private Map<Description, Boolean> shouldRunAnswers = new HashMap<Description, Boolean>();
-
public GroupMatcherCategoryFilter( GroupMatcher included, GroupMatcher excluded )
{
GroupMatcher invertedExclude = excluded == null ? null : new InverseGroupMatcher( excluded );
@@ -217,27 +176,15 @@ public class FilterFactory
private boolean shouldRun( Description description, Description parent )
{
- Boolean result = shouldRunAnswers.get( description );
- if ( result != null )
- {
- return result;
- }
-
if ( matcher == null )
{
return true;
}
- // System.out.println( "\n\nMatcher: " + matcher );
- // System.out.println( "Checking: " + description.getClassName()
- // + ( parent == null ? "" : "#" + description.getMethodName() ) );
-
Set<Class<?>> cats = new HashSet<Class<?>>();
Category cat = description.getAnnotation( Category.class );
if ( cat != null )
{
- // System.out.println( "Adding categories: " + Arrays.toString(
- // cat.value() ) );
cats.addAll( Arrays.asList( cat.value() ) );
}
@@ -246,26 +193,16 @@ public class FilterFactory
cat = parent.getAnnotation( Category.class );
if ( cat != null )
{
- // System.out.println( "Adding class-level categories: " +
- // Arrays.toString( cat.value() ) );
cats.addAll( Arrays.asList( cat.value() ) );
}
}
- // System.out.println( "Checking " + cats.size() + " categories..."
- // );
- //
- // System.out.println( "Enabled? " + ( matcher.enabled(
- // cats.toArray( new Class<?>[] {} ) ) ) + "\n\n" );
- result = matcher.enabled( cats.toArray( new Class<?>[] {} ) );
+ boolean result = matcher.enabled( cats.toArray( new Class<?>[] {} ) );
if ( parent == null )
{
if ( cats.size() == 0 )
{
- // System.out.println(
- // "Allow method-level filtering by PASSing class-level shouldRun() test..."
- // );
result = true;
}
else if ( !result )
@@ -285,8 +222,7 @@ public class FilterFactory
}
}
- shouldRunAnswers.put( description, result );
- return result == null ? false : result;
+ return result;
}
@Override