@@ -43,8 +43,8 @@ public class TestSplit {
4343 private final @ NotNull String glob ;
4444 private final @ Nullable String excludeGlob ;
4545 private final @ Nullable String junitGlob ;
46- private final @ NotNull FormatOption format ;
47- private final boolean useAverageTimeForNewTests ;
46+ private final @ NotNull FormatOption formatOption ;
47+ private final @ NotNull NewTestTimeOption newTestTimeOption ;
4848 private final @ NotNull Path workingDirectory ;
4949 private final boolean debug ;
5050 private final @ NotNull Consumer <Integer > exitCodeConsumer ;
@@ -55,8 +55,8 @@ public TestSplit(
5555 final @ NotNull String glob ,
5656 final @ Nullable String excludeGlob ,
5757 final @ Nullable String junitGlob ,
58- final @ NotNull FormatOption format ,
59- final boolean useAverageTimeForNewTests ,
58+ final @ NotNull FormatOption formatOption ,
59+ final @ NotNull NewTestTimeOption newTestTimeOption ,
6060 final @ NotNull Path workingDirectory ,
6161 final boolean debug ,
6262 final @ NotNull Consumer <Integer > exitCodeConsumer ) {
@@ -65,8 +65,8 @@ public TestSplit(
6565 this .glob = glob ;
6666 this .excludeGlob = excludeGlob ;
6767 this .junitGlob = junitGlob ;
68- this .format = format ;
69- this .useAverageTimeForNewTests = useAverageTimeForNewTests ;
68+ this .formatOption = formatOption ;
69+ this .newTestTimeOption = newTestTimeOption ;
7070 this .workingDirectory = workingDirectory ;
7171 this .debug = debug ;
7272 this .exitCodeConsumer = exitCodeConsumer ;
@@ -82,7 +82,7 @@ public TestSplit(
8282 if (junitGlob != null ) {
8383 LOG .info ("JUnit glob: {}" , junitGlob );
8484 }
85- LOG .info ("Output format: {}" , format );
85+ LOG .info ("Output format: {}" , formatOption );
8686 final var testPaths = getPaths (workingDirectory , glob , excludeGlob );
8787 final var classNames = fileToClassName (testPaths , exitCodeConsumer );
8888 if (classNames .isEmpty ()) {
@@ -119,11 +119,11 @@ public TestSplit(
119119 }
120120 }
121121 // add tests without timing records
122- final var newTestTime = getNewTestTime (useAverageTimeForNewTests , testCases );
122+ final var newTestTime = getNewTestTime (newTestTimeOption , testCases );
123123 classNames .forEach (className -> {
124124 final var testCase = new TestCase (className , newTestTime );
125125 if (testCases .add (testCase )) {
126- LOG .debug ("Adding test {}" , testCase .name ());
126+ LOG .debug ("Adding test {} [estimated {}] " , testCase .name (), formatTime ( testCase . time () ));
127127 }
128128 });
129129
@@ -164,7 +164,7 @@ public TestSplit(
164164 .stream ()
165165 .sorted (Comparator .reverseOrder ())
166166 .map (TestCase ::name )
167- .map (test -> switch (format ) {
167+ .map (test -> switch (formatOption ) {
168168 case LIST -> test ;
169169 case GRADLE -> "--tests " + test ;
170170 })
@@ -243,13 +243,29 @@ public TestSplit(
243243 }
244244
245245 private static double getNewTestTime (
246- final boolean useAverageTimeForNewTests ,
246+ final @ NotNull NewTestTimeOption useAverageTimeForNewTests ,
247247 final @ NotNull Set <TestCase > testCases ) {
248- if (! useAverageTimeForNewTests || testCases .isEmpty ()) {
248+ if (testCases .isEmpty ()) {
249249 return 0d ;
250250 }
251- final var averageTime = testCases .stream ().mapToDouble (TestCase ::time ).sum () / (double ) testCases .size ();
252- LOG .info ("Average test time is {}" , formatTime (averageTime ));
253- return averageTime ;
251+ return switch (useAverageTimeForNewTests ) {
252+ case ZERO -> 0d ;
253+ case AVERAGE -> {
254+ final var averageTime =
255+ testCases .stream ().mapToDouble (TestCase ::time ).sum () / (double ) testCases .size ();
256+ LOG .info ("Average test time is {}" , formatTime (averageTime ));
257+ yield averageTime ;
258+ }
259+ case MIN -> {
260+ final var minTime = testCases .stream ().mapToDouble (TestCase ::time ).min ().orElseThrow ();
261+ LOG .info ("Minimum test time is {}" , formatTime (minTime ));
262+ yield minTime ;
263+ }
264+ case MAX -> {
265+ final var maxTime = testCases .stream ().mapToDouble (TestCase ::time ).max ().orElseThrow ();
266+ LOG .info ("Maximum test time is {}" , formatTime (maxTime ));
267+ yield maxTime ;
268+ }
269+ };
254270 }
255271}
0 commit comments