Skip to content

Commit

Permalink
update the comparator to check positive and negtive numbers and 0 (#8)
Browse files Browse the repository at this point in the history
* update the comparator to check positive and negtive numbers and 0

* remove unused import
  • Loading branch information
waterlooyh authored Apr 16, 2021
1 parent 0972a52 commit 17cfb52
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,6 @@ public Integer testOrderComparator( String className1, String className2, String

String test1 = classFileName1 + "#" + methodName1;
String test2 = classFileName2 + "#" + methodName2;
if ( patternMapper.get( test1 ) < patternMapper.get( test2 ) )
{
return -1;
}
else
{
return 1;
}
return patternMapper.get( test1 ) - patternMapper.get( test2 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
import org.apache.maven.surefire.api.testset.RunOrderParameters;
import org.apache.maven.surefire.api.testset.TestListResolver;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -123,7 +119,7 @@ public int compare( String o1, String o2 )

public TestListResolver getTestListResolver()
{
String orderParam = parseTestOrder( System.getProperty( "test" ) );
String orderParam = System.getProperty( "test" );
if ( orderParam == null )
{
throw new IllegalStateException( "TestListResolver in RunOrderCalculator should be used only when "
Expand Down Expand Up @@ -193,33 +189,6 @@ else if ( sortOrder != null )
}
}

private String parseTestOrder( String s )
{
// if s is a file, then parse each line of the file as a test
if ( s != null && s != "" )
{
File f = new File( s );
if ( f.exists() && !f.isDirectory ( ) )
{
try
{
List<String> l = Files.readAllLines( f.toPath(), Charset.defaultCharset( ) );
StringBuilder sb = new StringBuilder( );
for ( String sd : l )
{
sb.append( sd + "," );
}
String sd = sb.toString( );
return sd.substring( 0 , sd.length( ) - 1 );
}
catch ( IOException e )
{
}
}
}
return s;
}

private Comparator<Class> getSortOrderComparator( RunOrder runOrder )
{
if ( RunOrder.ALPHABETICAL.equals( runOrder ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,16 @@ public void testOrderComparatorTest()
TestListResolver tlr = new TestListResolver( orderParamList );
String className = "TestClass1";
String className2 = "TestClass2";
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testa2d", "testa1b" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testa2d", "testabc" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testa1b", "testabc" ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testa2d", "testaBc" ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testa3d", "testa1b" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className2, "testa2d", "testa1b" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className2, className, "testaBc", "testa1b" ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className2, "testa3d", "testa1b" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className2, "testa2d", "testabc" ), 1 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa2d", "testa1b" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa2d", "testabc" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa1b", "testabc" ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa2d", "testaBc" ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa3d", "testa1b" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className2, "testa2d", "testa1b" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className2, className, "testaBc", "testa1b" ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className2, "testa3d", "testa1b" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className2, "testa2d", "testabc" ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa2d", "testa2d" ) == 0 );
}

public void testRegexMethodOrderComparator()
Expand All @@ -537,16 +538,17 @@ public void testRegexMethodOrderComparator()
TestListResolver tlr = new TestListResolver( orderParamList );
String className = "TestClass1";
String className2 = "TestClass2";
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testabc", "testa1b" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testaBc", "testa2b" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testa1b", "testa3c" ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testa1b", "testa4b" ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className, "testa4b", "testabc" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className2, "testa1b", "test1123" ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className2, className, "testa1b", "testa1b" ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className2, className2, "testa1b", "test1123" ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className2, className2, "test1123", "test11MyTest" ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className2, className2, "test11MyTest", "test456" ), -1 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testabc", "testa1b" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testaBc", "testa2b" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa1b", "testa3c" ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa1b", "testa4b" ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa4b", "testabc" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className2, "testa1b", "test1123" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className2, className, "testa1b", "testa1b" ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className2, className2, "testa1b", "test1123" ) == 0 );
assertTrue( ( int ) tlr.testOrderComparator( className2, className2, "test1123", "test11MyTest" ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className2, className2, "test11MyTest", "test456" ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, "testa1c", "testa1c" ) == 0 );
}

public void testRegexClassOrderComparator()
Expand All @@ -559,9 +561,10 @@ public void testRegexClassOrderComparator()
String className = "My2ConnectTest";
String className2 = "456My1ConnectTest";
String className3 = "abcMy1PeaceTest";
assertEquals( ( int ) tlr.testOrderComparator( className, className2, null, null ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className2, className, null, null ), 1 );
assertEquals( ( int ) tlr.testOrderComparator( className3, className2, null, null ), -1 );
assertEquals( ( int ) tlr.testOrderComparator( className, className3, null, null ), 1 );
assertTrue( ( int ) tlr.testOrderComparator( className, className2, null, null ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className2, className, null, null ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className3, className2, null, null ) < 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className3, null, null ) > 0 );
assertTrue( ( int ) tlr.testOrderComparator( className, className, null, null ) == 0 );
}
}

0 comments on commit 17cfb52

Please sign in to comment.