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/06/06 21:27:15 UTC

git commit: [SUREFIRE-829] Support inheritance while running test cases belonging to a particular category/group Submitted by: Gayathri Muralidharan

Updated Branches:
  refs/heads/master ddcd08348 -> 8980aa562


[SUREFIRE-829] Support inheritance while running test cases belonging to a particular category/group
Submitted by: Gayathri Muralidharan

o Suggested changes in FilterFactory had to be rewritten, as the code has changed significantly compared to the patch reference


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/8980aa56
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/8980aa56
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/8980aa56

Branch: refs/heads/master
Commit: 8980aa5623899d635302a3bede53f0ce8a2081f3
Parents: ddcd083
Author: Andreas Gudian <ag...@apache.org>
Authored: Thu Jun 6 21:26:32 2013 +0200
Committer: Andreas Gudian <ag...@apache.org>
Committed: Thu Jun 6 21:26:32 2013 +0200

----------------------------------------------------------------------
 .../surefire/common/junit48/FilterFactory.java     |   41 +++++++++++++--
 .../surefire/common/junit48/JUnit48Reflector.java  |    4 +-
 .../common/junit48/JUnit48ReflectorTest.java       |    6 ++
 3 files changed, 45 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/8980aa56/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 2386c8d..f3fcc0b 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,6 +21,8 @@ package org.apache.maven.surefire.common.junit48;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Properties;
@@ -169,12 +171,36 @@ public class FilterFactory
         @Override
         public boolean shouldRun( Description description )
         {
-            return shouldRun( description,
-                              ( ( description.getMethodName() == null || description.getTestClass() == null ) ? null
-                                              : Description.createSuiteDescription( description.getTestClass() ) ) );
+            if ( description.getMethodName() == null || description.getTestClass() == null )
+            {
+                return shouldRun( description, null, null );
+            }
+            else
+            {
+                return shouldRun( description, Description.createSuiteDescription( description.getTestClass() ),
+                                  description.getTestClass() );
+            }
+        }
+
+        private Collection<Class<?>> findSuperclassCategories( Class<?> clazz )
+        {
+            if ( clazz != null && clazz.getSuperclass() != null )
+            {
+                Category cat = clazz.getSuperclass().getAnnotation( Category.class );
+                if ( cat != null )
+                {
+                    return new HashSet<Class<?>>( Arrays.asList( cat.value() ) );
+                }
+                else
+                {
+                    return findSuperclassCategories( clazz.getSuperclass() );
+                }
+            }
+
+            return Collections.emptySet();
         }
 
-        private boolean shouldRun( Description description, Description parent )
+        private boolean shouldRun( Description description, Description parent, Class<?> parentClass )
         {
             if ( matcher == null )
             {
@@ -197,6 +223,11 @@ public class FilterFactory
                 }
             }
 
+            if ( parentClass != null )
+            {
+                cats.addAll( findSuperclassCategories( parentClass ) );
+            }
+
             boolean result = matcher.enabled( cats.toArray( new Class<?>[] {} ) );
 
             if ( parent == null )
@@ -212,7 +243,7 @@ public class FilterFactory
                     {
                         for ( Description child : children )
                         {
-                            if ( shouldRun( child, description ) )
+                            if ( shouldRun( child, description, null ) )
                             {
                                 result = true;
                                 break;

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/8980aa56/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java
index cb7f159..44b12c2 100644
--- a/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java
+++ b/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/JUnit48Reflector.java
@@ -47,6 +47,8 @@ public final class JUnit48Reflector
 
     public boolean isCategoryAnnotationPresent( Class clazz )
     {
-        return category != null && clazz.getAnnotation( category ) != null;
+        return ( category != null &&
+                        ( clazz.getAnnotation( category ) != null 
+                        || ( clazz.getSuperclass() != null && isCategoryAnnotationPresent( clazz.getSuperclass() ) ) ) );
     }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/8980aa56/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit48ReflectorTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit48ReflectorTest.java b/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit48ReflectorTest.java
index 465b4c9..fe4a884 100644
--- a/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit48ReflectorTest.java
+++ b/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit48ReflectorTest.java
@@ -40,6 +40,7 @@ public class JUnit48ReflectorTest
     {
         JUnit48Reflector jUnit48Reflector = new JUnit48Reflector( this.getClass().getClassLoader() );
         assertTrue( jUnit48Reflector.isCategoryAnnotationPresent( Test1.class ) );
+        assertTrue( jUnit48Reflector.isCategoryAnnotationPresent( Test3.class ) );
         assertFalse( jUnit48Reflector.isCategoryAnnotationPresent( Test2.class ) );
     }
 
@@ -59,4 +60,9 @@ public class JUnit48ReflectorTest
 
     }
 
+    private class Test3
+        extends Test1
+    {
+
+    }
 }