IoannisDermitzakis commented on a change in pull request #248: SUREFIRE-1695 
Support multiple inheritance of @Categories
URL: https://github.com/apache/maven-surefire/pull/248#discussion_r328453423
 
 

 ##########
 File path: 
surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/GroupMatcherCategoryFilter.java
 ##########
 @@ -63,33 +63,50 @@
     @Override
     public boolean shouldRun( Description description )
     {
-        if ( description.getMethodName() == null || description.getTestClass() 
== null )
-        {
+        if(invalidTestClass(description)){
             return shouldRun( description, null, null );
         }
-        else
+
+        if (describesTestClass(description)) // is a test class
+        {
+            Class<?> testClass = description.getTestClass();
+            return shouldRun( description, null, testClass );
+        }
+        else // is a test method
         {
             Class<?> testClass = description.getTestClass();
             return shouldRun( description, createSuiteDescription( testClass 
), testClass );
         }
     }
 
+    private boolean describesTestClass(Description description) {
+        // Description parser in Junit 4.8 can return "null" String.
+        return description.getMethodName() == null || 
description.getMethodName().equals("null");
+    }
+
+    private boolean invalidTestClass(Description description) {
+        return description.getTestClass() == null;
+    }
+
     private static void findSuperclassCategories( Set<Class<?>> cats, Class<?> 
clazz )
     {
-        if ( clazz != null && clazz.getSuperclass() != null )
+        if (hasSuperclass(clazz))
         {
             Category cat = clazz.getSuperclass().getAnnotation( Category.class 
);
             if ( cat != null )
             {
+                // Found categories in current superclass
                 addAll( cats, cat.value() );
             }
-            else
-            {
-                findSuperclassCategories( cats, clazz.getSuperclass() );
-            }
+            // Search the hierarchy
+            findSuperclassCategories( cats, clazz.getSuperclass() );
 
 Review comment:
   > Are you talking about class inheritance/override?
   > You have to distinguish between versions `4.11` or prior, and `4.12`. 
Notice that the Category is annotated `@Inherited` since of `4.12`, see this 
difference:
   > 
https://static.javadoc.io/junit/junit/4.11/org/junit/experimental/categories/Category.html
   > 
https://static.javadoc.io/junit/junit/4.12/org/junit/experimental/categories/Category.html
   > You have to check that the `@Inherited` exists on the annotation 
`@Category`.
   
   Ok so if I understand correctly, checking for presence of @Inherited in the 
annotation should suffice to decide whether to look in the superclass for 
categories.. If it is absent then the categories of the superclass should be 
ignored.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to