Skip to content

Commit 45f4aa8

Browse files
committed
Use thenComparing with key extractor and comparator
1 parent cafaaa6 commit 45f4aa8

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/WorkerThreadPoolHierarchicalTestExecutorService.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,10 @@ public Iterator<Entry> iterator() {
694694

695695
private static final class Entry {
696696

697-
private static final Comparator<Entry> SAME_LENGTH_UNIQUE_ID_COMPARATOR //
698-
= (e1, e2) -> compareBy(e1.uniqueId(), e2.uniqueId());
699-
700697
private static final Comparator<Entry> QUEUE_COMPARATOR = comparing(Entry::level).reversed() //
701698
.thenComparing(Entry::isContainer) // tests before containers
702699
.thenComparing(Entry::index) //
703-
.thenComparing(SAME_LENGTH_UNIQUE_ID_COMPARATOR);
700+
.thenComparing(Entry::uniqueId, new SameLengthUniqueIdComparator());
704701

705702
private static final Comparator<Entry> CHILD_COMPARATOR = comparing(Entry::isContainer).reversed() // containers before tests
706703
.thenComparing(Entry::index);
@@ -724,30 +721,6 @@ private static final class Entry {
724721
this.index = index;
725722
}
726723

727-
private static int compareBy(UniqueId a, UniqueId b) {
728-
var aIterator = a.getSegments().iterator();
729-
var bIterator = b.getSegments().iterator();
730-
731-
// ids have the same length
732-
while (aIterator.hasNext()) {
733-
var aCurrent = aIterator.next();
734-
var bCurrent = bIterator.next();
735-
int result = compareBy(aCurrent, bCurrent);
736-
if (result != 0) {
737-
return result;
738-
}
739-
}
740-
return 0;
741-
}
742-
743-
private static int compareBy(UniqueId.Segment a, UniqueId.Segment b) {
744-
int result = a.getType().compareTo(b.getType());
745-
if (result != 0) {
746-
return result;
747-
}
748-
return a.getValue().compareTo(b.getValue());
749-
}
750-
751724
private int index() {
752725
return this.index;
753726
}
@@ -793,6 +766,34 @@ public String toString() {
793766
.toString();
794767
}
795768

769+
private static class SameLengthUniqueIdComparator implements Comparator<UniqueId> {
770+
771+
@Override
772+
public int compare(UniqueId a, UniqueId b) {
773+
var aIterator = a.getSegments().iterator();
774+
var bIterator = b.getSegments().iterator();
775+
776+
// ids have the same length
777+
while (aIterator.hasNext()) {
778+
var aCurrent = aIterator.next();
779+
var bCurrent = bIterator.next();
780+
int result = compareBy(aCurrent, bCurrent);
781+
if (result != 0) {
782+
return result;
783+
}
784+
}
785+
return 0;
786+
}
787+
788+
private static int compareBy(UniqueId.Segment a, UniqueId.Segment b) {
789+
int result = a.getType().compareTo(b.getType());
790+
if (result != 0) {
791+
return result;
792+
}
793+
return a.getValue().compareTo(b.getValue());
794+
}
795+
}
796+
796797
}
797798
}
798799

0 commit comments

Comments
 (0)