Skip to content

Commit 1c06971

Browse files
committed
immutable RunOrderParameters
1 parent f2d28b8 commit 1c06971

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

surefire-api/src/main/java/org/apache/maven/surefire/api/testset/RunOrderParameters.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class RunOrderParameters
2929
{
3030
private final RunOrder[] runOrder;
3131

32-
private File runStatisticsFile;
32+
private final File runStatisticsFile;
3333

34-
private Long runOrderRandomSeed;
34+
private final Long runOrderRandomSeed;
3535

3636
public RunOrderParameters( RunOrder[] runOrder, File runStatisticsFile )
3737
{
@@ -76,11 +76,6 @@ public Long getRunOrderRandomSeed()
7676
return runOrderRandomSeed;
7777
}
7878

79-
public void setRunOrderRandomSeed( Long runOrderRandomSeed )
80-
{
81-
this.runOrderRandomSeed = runOrderRandomSeed;
82-
}
83-
8479
public File getRunStatisticsFile()
8580
{
8681
return runStatisticsFile;

surefire-api/src/main/java/org/apache/maven/surefire/api/util/DefaultRunOrderCalculator.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
public class DefaultRunOrderCalculator
3939
implements RunOrderCalculator
4040
{
41-
private final Comparator<Class> sortOrder;
41+
private final Comparator<Class<?>> sortOrder;
4242

4343
private final RunOrder[] runOrder;
4444

@@ -55,12 +55,7 @@ public DefaultRunOrderCalculator( RunOrderParameters runOrderParameters, int thr
5555
this.runOrder = runOrderParameters.getRunOrder();
5656
this.sortOrder = this.runOrder.length > 0 ? getSortOrderComparator( this.runOrder[0] ) : null;
5757
Long runOrderRandomSeed = runOrderParameters.getRunOrderRandomSeed();
58-
if ( runOrderRandomSeed == null )
59-
{
60-
runOrderRandomSeed = System.nanoTime();
61-
runOrderParameters.setRunOrderRandomSeed( runOrderRandomSeed );
62-
}
63-
this.random = new Random( runOrderRandomSeed );
58+
this.random = new Random( runOrderRandomSeed == null ? System.nanoTime() : runOrderRandomSeed );
6459
}
6560

6661
@Override
@@ -102,11 +97,11 @@ else if ( RunOrder.BALANCED.equals( runOrder ) )
10297
}
10398
else if ( sortOrder != null )
10499
{
105-
Collections.sort( testClasses, sortOrder );
100+
testClasses.sort( sortOrder );
106101
}
107102
}
108103

109-
private Comparator<Class> getSortOrderComparator( RunOrder runOrder )
104+
private static Comparator<Class<?>> getSortOrderComparator( RunOrder runOrder )
110105
{
111106
if ( RunOrder.ALPHABETICAL.equals( runOrder ) )
112107
{
@@ -127,27 +122,13 @@ else if ( RunOrder.HOURLY.equals( runOrder ) )
127122
}
128123
}
129124

130-
private Comparator<Class> getReverseAlphabeticalComparator()
125+
private static Comparator<Class<?>> getReverseAlphabeticalComparator()
131126
{
132-
return new Comparator<Class>()
133-
{
134-
@Override
135-
public int compare( Class o1, Class o2 )
136-
{
137-
return o2.getName().compareTo( o1.getName() );
138-
}
139-
};
127+
return ( o1, o2 ) -> o2.getName().compareTo( o1.getName() );
140128
}
141129

142-
private Comparator<Class> getAlphabeticalComparator()
130+
private static Comparator<Class<?>> getAlphabeticalComparator()
143131
{
144-
return new Comparator<Class>()
145-
{
146-
@Override
147-
public int compare( Class o1, Class o2 )
148-
{
149-
return o1.getName().compareTo( o2.getName() );
150-
}
151-
};
132+
return Comparator.comparing( Class::getName );
152133
}
153134
}

0 commit comments

Comments
 (0)