slawekjaranowski commented on a change in pull request #400:
URL: https://github.com/apache/maven-surefire/pull/400#discussion_r773294587
##########
File path:
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
##########
@@ -1839,14 +1842,38 @@ private PluginFailureReason getEffectiveFailIfNoTests()
{
if ( isSpecificTestSpecified() )
{
- return getFailIfNoSpecifiedTests() ? COULD_NOT_RUN_SPECIFIED_TESTS
: NONE;
+ if ( getFailIfNoSpecifiedTests()
+ && isTestToIncludeExcludeNoSpecified() )
+ {
+ return COULD_NOT_RUN_SPECIFIED_TESTS;
+ }
+ else
+ {
+ return NONE;
+ }
}
else
{
return getFailIfNoTests() ? COULD_NOT_RUN_DEFAULT_TESTS : NONE;
}
}
+ private boolean isTestToIncludeExcludeNoSpecified()
+ {
+ return getTestToIncludeExclude().isEmpty();
+ }
+
+ private void setTestToIncludeExclude( String test )
+ {
+ this.testToIncludeExclude = test;
+ setTest( test );
+ }
Review comment:
mixed responsibility ..
when I see a call some setter method I expect that one property will be set
...
##########
File path:
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
##########
@@ -2282,32 +2336,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();
Review comment:
`includeList` is return value from `getIncludeList` should be immutable
...
##########
File path:
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
##########
@@ -2271,7 +2324,8 @@ private void maybeAppendList( List<String> base,
List<String> list )
maybeAppendList( includes, getIncludes() );
}
- checkMethodFilterInIncludesExcludes( includes );
+ List<String> methodFilterInIncludes =
getMethodFilterInIncludesExcludes( includes );
+ addAll( includes, methodFilterInIncludes.toArray( new String[0] )
);
Review comment:
`includes` can be reference to anything - should be immutable
##########
File path:
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
##########
@@ -2282,32 +2336,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, "," ) ) )
+ {
+ setTestToIncludeExclude( testToIncludeExclude );
+ }
+ includedExcludedTests = new TestListResolver( includeList,
excludeList.getTestClasses() );
+ }
}
return includedExcludedTests;
}
+
+ class IncludeExcludeList
+ {
+
+ private List<String> testClasses = new LinkedList<>();
+
+ private List<String> testMethods = new LinkedList<>();
+
+ IncludeExcludeList( List<String> testClasses, List<String> testMethods
)
+ {
+ super();
Review comment:
needed?
--
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]