TestSorter () { String sorter = System.getProperty("intellij.build.test.sorter"); // use Nostradamus test sorter in case, if no other is specified if (sorter == null && IS_NASTRADAMUS_TEST_DISTRIBUTOR_ENABLED) { sorter = "com.intellij.nastradamus.NastradamusTestCaseSorter"; } if (sorter != null) { try { var testSorter = (TestSorter)Class.forName(sorter).getConstructor().newInstance(); System.out.printf("Using test sorter from %s%n", sorter); return testSorter; } catch (Throwable t) { System.err.println("Sorter initialization failed: " + sorter); t.printStackTrace(); } } if (IS_VERBOSE_LOG_ENABLED) { System.out.println("Using default test sorter (natural order)"); } Comparator<String> classNameComparator = REVERSE_ORDER ? Comparator.reverseOrder() : Comparator.naturalOrder(); return new TestSorter() { @Override public @NotNull List<Class<?>> sorted(@NotNull List<Class<?>> testClasses, @NotNull ToIntFunction<? super Class<?>> ranker) { return ContainerUtil.sorted(testClasses, Comparator.<Class<?>>comparingInt(ranker).thenComparing(Class::getName, classNameComparator)); } }; }