Skip to content

Commit

Permalink
Refactor option handling to simplify revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbabcoc committed Apr 9, 2022
1 parent 86f5e28 commit bdcf3a0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
Expand Up @@ -23,6 +23,7 @@
import org.testng.xml.XmlSuite;

import java.util.Map;

import static org.apache.maven.surefire.api.booter.ProviderParameterNames.PARALLEL_PROP;
import static org.apache.maven.surefire.api.booter.ProviderParameterNames.THREADCOUNT_PROP;
import static org.apache.maven.surefire.api.util.ReflectionUtils.invokeSetter;
Expand All @@ -39,26 +40,38 @@ public class TestNG740Configurator
extends TestNG60Configurator
{
@Override
public void configure( XmlSuite suite, Map<String, String> options )
protected void configureThreadCount( XmlSuite suite, Map<String, String> options )
throws TestSetFailedException
{
// if [threadcount] option in unspecified
if ( !options.containsKey( THREADCOUNT_PROP ) )
String threadCount = options.get( THREADCOUNT_PROP );
// if [threadcount] spec'd
if ( threadCount != null )
{
// acquire default [threadcount] value to avoid superclass hardcoding to 1
options.put( THREADCOUNT_PROP, Integer.toString( suite.getThreadCount() ) );
try
{
// convert and apply [threadcount] setting
suite.setThreadCount( Integer.parseInt( threadCount ) );
}
catch ( NumberFormatException e )
{
throw new TestSetFailedException( "Non-integer TestNG [threadcount] setting: " + threadCount, e );
}
}

// if [parallel] option is specified
if ( options.containsKey( PARALLEL_PROP ) )
}

@Override
protected void configureParallel( XmlSuite suite, Map<String, String> options )
throws TestSetFailedException
{
String parallel = options.get( PARALLEL_PROP );
// if [parallel] spec'd
if ( parallel != null )
{
// try to load the [ParallelMode] enumeration
Class enumClass = tryLoadClass( XmlSuite.class.getClassLoader(), "org.testng.xml.XmlSuite$ParallelMode" );
// if enumeration loaded
if ( enumClass != null )
{
// extract [parallel] option
String parallel = options.remove( PARALLEL_PROP );
try
{
// convert [parallel] option to corresponding constant
Expand All @@ -68,12 +81,14 @@ public void configure( XmlSuite suite, Map<String, String> options )
}
catch ( IllegalArgumentException e )
{
throw new TestSetFailedException( "Unsupported TestNG parallel setting: " + parallel, e );
throw new TestSetFailedException( "Unsupported TestNG [parallel] setting: " + parallel, e );
}
}
else
{
throw new TestSetFailedException(
"Failed loading TestNG [ParallelMode] enumeration to convert [parallel] setting: " + parallel );
}
}

// invoke superclass handler
super.configure( suite, options );
}
}
Expand Up @@ -60,11 +60,22 @@ public void configure( TestNG testng, Map<String, String> options )
@Override
public void configure( XmlSuite suite, Map<String, String> options )
throws TestSetFailedException
{
configureThreadCount( suite, options );
configureParallel( suite, options );
}

protected void configureThreadCount( XmlSuite suite, Map<String, String> options )
throws TestSetFailedException
{
String threadCountAsString = options.get( THREADCOUNT_PROP );
int threadCount = threadCountAsString == null ? 1 : parseInt( threadCountAsString );
suite.setThreadCount( threadCount );

}

protected void configureParallel( XmlSuite suite, Map<String, String> options )
throws TestSetFailedException
{
String parallel = options.get( PARALLEL_PROP );
if ( parallel != null )
{
Expand Down

0 comments on commit bdcf3a0

Please sign in to comment.