Skip to content

Commit d307f4c

Browse files
committed
Clean up project
1 parent dd5c103 commit d307f4c

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

src/main/java/de/donnerbart/split/TestLoader.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public TestLoader(
107107
return testCases;
108108
}
109109

110-
private @NotNull Set<Path> getPaths(
110+
private static @NotNull Set<Path> getPaths(
111111
final @NotNull Path rootPath,
112112
final @NotNull String glob,
113113
final @Nullable String excludeGlob) throws Exception {
@@ -140,7 +140,7 @@ public TestLoader(
140140
return files;
141141
}
142142

143-
private @NotNull Set<String> fileToClassName(
143+
private static @NotNull Set<String> fileToClassName(
144144
final @NotNull Set<Path> testPaths,
145145
final @NotNull Consumer<Integer> exitCodeConsumer) {
146146
final var javaParser = new JavaParser();
@@ -161,13 +161,15 @@ public TestLoader(
161161
.stream()
162162
.map(NodeWithName::getNameAsString)
163163
.anyMatch(SKIP_TEST_IMPORTS::contains);
164-
final var hasSkipTestAnnotation = declaration.getAnnotations()
165-
.stream()
166-
.map(AnnotationExpr::getNameAsString)
167-
.anyMatch(SKIP_TEST_ANNOTATIONS::contains);
168-
if (hasSkipTestImport && hasSkipTestAnnotation) {
169-
LOG.info("Skipping disabled test class {}", className);
170-
continue;
164+
if (hasSkipTestImport) {
165+
final var hasSkipTestAnnotation = declaration.getAnnotations()
166+
.stream()
167+
.map(AnnotationExpr::getNameAsString)
168+
.anyMatch(SKIP_TEST_ANNOTATIONS::contains);
169+
if (hasSkipTestAnnotation) {
170+
LOG.info("Skipping disabled test class {}", className);
171+
continue;
172+
}
171173
}
172174
classNames.add(className);
173175
} catch (final Exception e) {
@@ -178,7 +180,7 @@ public TestLoader(
178180
return classNames;
179181
}
180182

181-
private double getNewTestTime(
183+
private static double getNewTestTime(
182184
final @NotNull NewTestTimeOption useAverageTimeForNewTests,
183185
final @NotNull Set<TestCase> testCases) {
184186
if (testCases.isEmpty()) {

src/main/java/de/donnerbart/split/TestSplit.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.jetbrains.annotations.NotNull;
66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
8-
import org.slf4j.helpers.NOPLogger;
98

109
import java.util.Comparator;
1110
import java.util.Set;
@@ -14,51 +13,54 @@
1413

1514
public class TestSplit {
1615

16+
private static final @NotNull Logger LOG = LoggerFactory.getLogger(TestSplit.class);
17+
1718
private final @NotNull Set<TestCase> testCases;
1819
private final int splitTotal;
1920
private final @NotNull FormatOption formatOption;
20-
private final @NotNull Logger log;
2121
private final boolean debug;
2222

2323
public TestSplit(
2424
final @NotNull Set<TestCase> testCases,
2525
final int splitTotal,
2626
final @NotNull FormatOption formatOption,
27-
final boolean log,
2827
final boolean debug) {
2928
this.testCases = testCases;
3029
this.splitTotal = splitTotal;
3130
this.formatOption = formatOption;
32-
this.log = log ? LoggerFactory.getLogger(TestSplit.class) : NOPLogger.NOP_LOGGER;
3331
this.debug = debug;
3432
}
3533

3634
public @NotNull Splits split() {
3735
// split tests
38-
log.debug("Splitting {} tests", testCases.size());
36+
if (debug) {
37+
LOG.debug("Splitting {} tests", testCases.size());
38+
}
3939
final var splits = new Splits(splitTotal, formatOption);
4040
testCases.stream().sorted(Comparator.reverseOrder()).forEach(testCase -> {
4141
final var split = splits.add(testCase);
42-
log.debug("Adding test {} to split #{}", testCase.name(), split.index());
42+
if (debug) {
43+
LOG.debug("Adding test {} to split #{}", testCase.name(), split.index());
44+
}
4345
});
4446

4547
if (debug) {
4648
if (splitTotal > 1) {
4749
final var fastestSplit = splits.getFastest();
48-
log.debug("Fastest test plan is #{} with {} tests ({})",
50+
LOG.debug("Fastest test plan is #{} with {} tests ({})",
4951
fastestSplit.formatIndex(),
5052
fastestSplit.tests().size(),
5153
formatTime(fastestSplit.totalRecordedTime()));
5254
final var slowestSplit = splits.getSlowest();
53-
log.debug("Slowest test plan is #{} with {} tests ({})",
55+
LOG.debug("Slowest test plan is #{} with {} tests ({})",
5456
slowestSplit.formatIndex(),
5557
slowestSplit.tests().size(),
5658
formatTime(slowestSplit.totalRecordedTime()));
57-
log.debug("Difference between the fastest and slowest test plan: {}",
59+
LOG.debug("Difference between the fastest and slowest test plan: {}",
5860
formatTime(slowestSplit.totalRecordedTime() - fastestSplit.totalRecordedTime()));
5961
}
60-
log.debug("Test splits:");
61-
splits.forEach(split -> log.debug(split.toString()));
62+
LOG.debug("Test splits:");
63+
splits.forEach(split -> LOG.debug(split.toString()));
6264
}
6365
return splits;
6466
}

src/main/java/de/donnerbart/split/TestSplitMain.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ public static void main(final @Nullable String @NotNull [] args) throws Exceptio
7878
if (arguments.calculateOptimalTotalSplit) {
7979
calculateOptimalTotalSplit(arguments, testCases);
8080
}
81-
final var testSplit =
82-
new TestSplit(testCases, arguments.splitTotal, arguments.formatOption, true, arguments.debug);
81+
final var testSplit = new TestSplit(testCases, arguments.splitTotal, arguments.formatOption, arguments.debug);
8382
final var splits = testSplit.split();
8483
final var split = splits.get(arguments.splitIndex);
8584
LOG.info("This test split has {} tests ({})", split.tests().size(), formatTime(split.totalRecordedTime()));
@@ -118,7 +117,7 @@ static int calculateOptimalTotalSplit(final @NotNull Arguments arguments, final
118117
var optimalSplit = 1;
119118
var lastSlowestSplit = Double.MAX_VALUE;
120119
while (true) {
121-
final var testSplit = new TestSplit(testCases, optimalSplit, arguments.formatOption, false, false);
120+
final var testSplit = new TestSplit(testCases, optimalSplit, arguments.formatOption, false);
122121
final var splits = testSplit.split();
123122
final var slowestSplit = splits.getSlowest().totalRecordedTime();
124123
if (Double.compare(slowestSplit, lastSlowestSplit) == 0) {

src/test/java/de/donnerbart/split/TestSplitTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void split_whitespaceClassDefinition() throws Exception {
317317
NewTestTimeOption.ZERO,
318318
tmp,
319319
exitCode::set);
320-
final var split = new TestSplit(testLoader.load(), 1, FormatOption.LIST, true, true);
320+
final var split = new TestSplit(testLoader.load(), 1, FormatOption.LIST, false);
321321

322322
final var splits = split.split();
323323
assertThat(splits.size()).isOne();
@@ -416,7 +416,7 @@ void split_noClassName() throws Exception {
416416
newTestTimeOption,
417417
workingDir,
418418
exitCode::set);
419-
final var testSplit = new TestSplit(testLoader.load(), splitTotal, formatOption, true, true);
419+
final var testSplit = new TestSplit(testLoader.load(), splitTotal, formatOption, true);
420420
final var splits = testSplit.split();
421421
final var result = new ArrayList<List<String>>(splitTotal);
422422
for (int index = 0; index < splitTotal; index++) {

0 commit comments

Comments
 (0)