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_r327954765
 
 

 ##########
 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:
   Hi, thanks for the Review! However, I don't understand this comment. Do you 
mean that a @Category in a subclass should override (i.e. replace) the classes 
in the @Category from the superclass? Because this is exactly the opposite of 
what I implemented.  I expect that the categories declared in the superclass 
are included as categories of the subclass, without needing to re-declare them. 

----------------------------------------------------------------
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