slawekjaranowski commented on a change in pull request #400:
URL: https://github.com/apache/maven-surefire/pull/400#discussion_r772573695



##########
File path: 
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
##########
@@ -2282,32 +2296,113 @@ private void maybeAppendList( List<String> base, 
List<String> list )
         return filterNulls( includes );
     }
 
-    private void checkMethodFilterInIncludesExcludes( Iterable<String> 
patterns )
-        throws MojoFailureException
+    private List<String> getMethodFilterInIncludesExcludes( Iterable<String> 
patterns )
     {
+        List<String> methodFilterInIncludesExcludes = new LinkedList<>();
         if ( patterns != null )
         {
             for ( String pattern : patterns )
             {
                 if ( pattern != null && pattern.contains( "#" ) )
                 {
-                    throw new MojoFailureException( "Method filter prohibited 
in "
-                                                        + 
"includes|excludes|includesFile|excludesFile parameter: "
-                                                        + pattern );
+                    methodFilterInIncludesExcludes.add( pattern );
                 }
             }
         }
+        return methodFilterInIncludesExcludes;
     }
 
     private TestListResolver getIncludedAndExcludedTests()
         throws MojoFailureException
     {
         if ( includedExcludedTests == null )
         {
-            includedExcludedTests = new TestListResolver( getIncludeList(), 
getExcludeList() );
+            StringBuilder sb = new StringBuilder();
+            List<String> includeList = getIncludeList();
+            for ( String include: includeList ) 
+            {
+                sb.append( "," ).append( include );
+            }
+            IncludeExcludeList excludeList = getExcludeList();
+            List<String> excludedTestMethods = excludeList.getTestMethods();
+            if ( !excludedTestMethods.isEmpty() ) 
+            {
+                includeList.clear();
+                includeList.addAll( excludedTestMethods );
+                for ( String method : excludedTestMethods ) 
+                {
+                  sb.append( "," ).append( method );
+                }
+            }
+            if ( !Arrays.equals( 
+                    Collections.singletonList( getDefaultExcludes() )
+                        .toArray( new String[0] ),
+                    excludeList.getTestClasses().toArray( new String[0] ) ) )
+            {
+                for ( String clazz : excludeList.getTestClasses() ) 
+                {
+                    sb.append( "," ).append( clazz );
+                }
+            }
+            
+            if ( sb.length() == 0 ) 
+            {
+                includedExcludedTests = new TestListResolver( 
+                        asList ( getDefaultIncludes() ), 
+                        Collections.singletonList( getDefaultExcludes() ) );
+            } 
+            else 
+            {
+                String testToIncludeExclude = sb.deleteCharAt( 0 ).toString( );
+                if ( !Arrays.equals( getDefaultIncludes(), split( 
testToIncludeExclude, "," ) ) ) 
+                {
+                    setTest( testToIncludeExclude );
+                }
+                includedExcludedTests = new TestListResolver( includeList, 
excludeList.getTestClasses() );
+            }

Review comment:
       There are many decision branches here.
   
   Maybe it will be possible put this logic in `TestListResolver` class and 
prepare unit test for it to cover all branches.
   
   Such tests can show which input params impact to result list.
   
   




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to