Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish reversealphabetical run order and test #5

Open
wants to merge 1 commit into
base: tms-only-runorder
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,60 @@ public Comparator<String> comparatorForTestMethods()
throw new IllegalStateException( "Unsupported number of runOrders. Expected 1. Got: " + runOrder.length );
}
RunOrder methodRunOrder = runOrder[0];
if ( RunOrder.TESTORDER.equals( methodRunOrder ) )
if ( RunOrder.REVERSE_ALPHABETICAL.equals( methodRunOrder ) )
{
String orderParam = parseTestOrder( System.getProperty( "test" ) );
if ( orderParam == null )
{
throw new IllegalStateException( "Please set system property -Dtest to use fixed order" );
}
final LinkedHashMap<String, List<String>> orders = new LinkedHashMap<>();
for ( String s : orderParam.split( "," ) )
{
String[] nameSplit = s.split( "#" );
String className = nameSplit[0];
String testName = nameSplit[1];
String parenName = testName + "(" + className + ")";
addTestToOrders( className, orders, parenName );
}
return new Comparator<String>()
{

@Override
public int compare( String o1, String o2 )
{
String className1 = o1;
String testName1 = o1;
if ( o1.contains( "(" ) )
{
String[] nameSplit1 = o1.split( "\\(" );
className1 = nameSplit1[1].substring( 0, nameSplit1[1].length() - 1 );
testName1 = nameSplit1[0];
addTestToOrders( className1, orders, o1 );
}

String className2 = o2;
String testName2 = o2;
if ( o2.contains( "(" ) )
{
String[] nameSplit2 = o2.split( "\\(" );
className2 = nameSplit2[1].substring( 0, nameSplit2[1].length() - 1 );
testName2 = nameSplit2[0];
addTestToOrders( className2, orders, o2 );
}

if ( ! className2.equals( className1 ) )
{
return className2.compareTo( className1 );
}
else
{
return testName2.compareTo( testName1 );
}
Comment on lines +138 to +145
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce duplication of code before this if/else block. You can move this if/else block to be lower and then just check for RunOrder.TESTORDER vs. RunOrder.REVERSEALPHEBETICAL at the necessary location

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reversealphabetical changes should be kept in this branch and another branch and pull request should be created to not have any reverse alphabetical related changes but still have new tests for TESTORDER

}
};
}
else if ( RunOrder.TESTORDER.equals( methodRunOrder ) )
{
String orderParam = parseTestOrder( System.getProperty( "test" ) );
if ( orderParam == null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;

import org.apache.maven.surefire.api.testset.RunOrderParameters;

Expand Down Expand Up @@ -59,4 +62,44 @@ static class B
{

}

public void reverseAlphabeticalRunOrderTestClasses()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Names of these tests are invalid, They must start with "test" for JUnit 3 to find and run them

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your new branch, repurpose all reversealphabetical tests to become TESTORDER tests.

{
getClassesToRun();
TestsToRun testsToRun = new TestsToRun( getClassesToRun() );
RunOrderParameters runOrderParameters = new RunOrderParameters( "reversealphabetical" , null );
RunOrderCalculator runOrderCalculator = new DefaultRunOrderCalculator( runOrderParameters, 1 );
final TestsToRun testsToRun1 = runOrderCalculator.orderTestClasses( testsToRun );
assertEquals( B.class, testsToRun1.iterator().next() );
}

public void reverseAlphabeticalRunOrderTestMethods()
{
RunOrderParameters runOrderParameters = new RunOrderParameters( "reversealphabetical" , null );
RunOrderCalculator runOrderCalculator = new DefaultRunOrderCalculator( runOrderParameters, 1 );
System.setProperty( "test", "org.apache.maven.surefire.api.util.RunOrderCalculatorTest$B#C,org.apache.maven.surefire.api.util.RunOrderCalculatorTest$B#D,org.apache.maven.surefire.api.util.RunOrderCalculatorTest$A#A,org.apache.maven.surefire.api.util.RunOrderCalculatorTest$A#B" );
Comparator<String> reverseAlphabeticalRunOrderComparator = runOrderCalculator.comparatorForTestMethods();
List<String> list = new ArrayList<String>();
list.add( "org.apache.maven.surefire.api.util.RunOrderCalculatorTest$B#A" );
list.add( "org.apache.maven.surefire.api.util.RunOrderCalculatorTest$B#B" );
list.add( "org.apache.maven.surefire.api.util.RunOrderCalculatorTest$A#C" );
list.add( "org.apache.maven.surefire.api.util.RunOrderCalculatorTest$A#D" );
list.sort( reverseAlphabeticalRunOrderComparator );
assertEquals( list.get(0), "org.apache.maven.surefire.api.util.RunOrderCalculatorTest$B#B" );
}

public void shouldThrowExceptionForNullTestMethod()
{
RunOrderParameters runOrderParameters = new RunOrderParameters( "reversealphabetical" , null );
RunOrderCalculator runOrderCalculator = new DefaultRunOrderCalculator( runOrderParameters, 1 );
System.clearProperty( "test" );
try
{
runOrderCalculator.comparatorForTestMethods();
}
catch ( IllegalStateException expected )
{
assertEquals( expected.getMessage(), "Please set system property -Dtest to use fixed order" );
}
}
}