Author: krosenvold Date: Mon Nov 14 21:51:16 2011 New Revision: 1201920 URL: http://svn.apache.org/viewvc?rev=1201920&view=rev Log: [SUREFIRE-789] Fail when missing category
Fixed based on testcase supplied by nkeywal Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/NoCategoryTest.java (with props) Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/BasicTest.java maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/CategoryCTest.java maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java?rev=1201920&r1=1201919&r2=1201920&view=diff ============================================================================== --- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java (original) +++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit48TestCategoriesIT.java Mon Nov 14 21:51:16 2011 @@ -52,7 +52,7 @@ public class JUnit48TestCategoriesIT { executeTest(); verifyErrorFreeLog(); - assertTestSuiteResults( 2, 0, 0, 0 ); + assertTestSuiteResults( 3, 0, 0, 0 ); verifyTextInLog("catA: 1"); verifyTextInLog("catB: 1"); verifyTextInLog("catC: 0"); Modified: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/BasicTest.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/BasicTest.java?rev=1201920&r1=1201919&r2=1201920&view=diff ============================================================================== --- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/BasicTest.java (original) +++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/BasicTest.java Mon Nov 14 21:51:16 2011 @@ -1,6 +1,24 @@ 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.AfterClass; -import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; Modified: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/CategoryCTest.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/CategoryCTest.java?rev=1201920&r1=1201919&r2=1201920&view=diff ============================================================================== --- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/CategoryCTest.java (original) +++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/CategoryCTest.java Mon Nov 14 21:51:16 2011 @@ -1,4 +1,23 @@ 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.AfterClass; import org.junit.Test; import org.junit.experimental.categories.Category; Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/NoCategoryTest.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/NoCategoryTest.java?rev=1201920&view=auto ============================================================================== --- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/NoCategoryTest.java (added) +++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/NoCategoryTest.java Mon Nov 14 21:51:16 2011 @@ -0,0 +1,38 @@ +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.AfterClass; +import org.junit.Test; + +public class NoCategoryTest { + static int catNoneCount = 0; + + @Test + public void testInNoCategory() + { + catNoneCount++; + } + + @AfterClass + public static void oneTimeTearDown() + { + System.out.println("NoCategoryTest.CatNone: " + catNoneCount); + } +} Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit48-categories/src/test/java/junit4/NoCategoryTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java?rev=1201920&r1=1201919&r2=1201920&view=diff ============================================================================== --- maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java (original) +++ maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java Mon Nov 14 21:51:16 2011 @@ -41,7 +41,6 @@ public class FilterFactory public Filter createGroupFilter( Properties providerProperties ) { - providerProperties.list( System.err ); String groups = providerProperties.getProperty( "groups" ); String excludedGroups = providerProperties.getProperty( "excludedgroups" ); List<Filter> included = commaSeparatedListToFilters( groups ); Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java?rev=1201920&r1=1201919&r2=1201920&view=diff ============================================================================== --- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java (original) +++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java Mon Nov 14 21:51:16 2011 @@ -19,6 +19,7 @@ package org.apache.maven.surefire.junitc * under the License. */ +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -128,7 +129,8 @@ public class JUnitCoreProvider { List<Class<?>> res = new ArrayList<Class<?>>( 500 ); TestsToRun max = scanClassPath(); - if (filter == null){ + if ( filter == null ) + { return max; } @@ -136,12 +138,25 @@ public class JUnitCoreProvider while ( it.hasNext() ) { Class<?> clazz = it.next(); - boolean isCategoryAnnotatedClass = jUnit48Reflector.isCategoryAnnotationPresent( clazz); + boolean isCategoryAnnotatedClass = jUnit48Reflector.isCategoryAnnotationPresent( clazz ); Description d = Description.createSuiteDescription( clazz ); - if ( !isCategoryAnnotatedClass || filter.shouldRun( d ) ) + if ( filter.shouldRun( d ) ) { res.add( clazz ); } + else + { + for ( Method method : clazz.getMethods() ) + { + final Description testDescription = + Description.createTestDescription( clazz, method.getName(), method.getAnnotations() ); + if ( filter.shouldRun( testDescription ) ) + { + res.add( clazz ); + break; + } + } + } } return new TestsToRun( res ); }