Skip to content

Commit 7844717

Browse files
committed
Run the in-process service's cases of each JDK from a class of its own
As FormatterCasesJava21Test and the others do: FormatterServiceImplJava21Test, Java25Test and Java28Test name the case folders of their JDK, and their ranges do not overlap.
1 parent b86ae66 commit 7844717

4 files changed

Lines changed: 54 additions & 26 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.palantir.javaformat.java;
16+
17+
import java.util.List;
18+
import org.junit.jupiter.api.DynamicTest;
19+
import org.junit.jupiter.api.TestFactory;
20+
import org.junit.jupiter.api.condition.EnabledForJreRange;
21+
import org.junit.jupiter.api.condition.JRE;
22+
import org.junit.jupiter.api.parallel.Execution;
23+
import org.junit.jupiter.api.parallel.ExecutionMode;
24+
25+
/** {@link FormatterServiceImplTest} on JDK 21 to 24, with the cases of JDK 21. */
26+
@EnabledForJreRange(max = JRE.JAVA_24)
27+
@Execution(ExecutionMode.CONCURRENT)
28+
final class FormatterServiceImplJava21Test {
29+
@TestFactory
30+
List<DynamicTest> replacesTheChangedLinesAsTheCommandLineDoes() throws Exception {
31+
return FormatterServiceImplTest.changedLinesIn("test-cases-java21");
32+
}
33+
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterServiceImplJava25Test.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import org.junit.jupiter.api.parallel.Execution;
2323
import org.junit.jupiter.api.parallel.ExecutionMode;
2424

25-
/** The cases under {@code test-cases-java25}, as {@link FormatterServiceImplTest} runs those of JDK 21. */
26-
@EnabledForJreRange(min = JRE.JAVA_25)
25+
/** {@link FormatterServiceImplTest} on JDK 25 to 27, with the cases of JDK 21 and 25. */
26+
@EnabledForJreRange(min = JRE.JAVA_25, max = JRE.JAVA_27)
2727
@Execution(ExecutionMode.CONCURRENT)
2828
final class FormatterServiceImplJava25Test {
2929
@TestFactory
3030
List<DynamicTest> replacesTheChangedLinesAsTheCommandLineDoes() throws Exception {
31-
return FormatterServiceImplTest.changedLinesIn("test-cases-java25");
31+
return FormatterServiceImplTest.changedLinesIn("test-cases-java21", "test-cases-java25");
3232
}
3333
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterServiceImplJava28Test.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import org.junit.jupiter.api.parallel.Execution;
2323
import org.junit.jupiter.api.parallel.ExecutionMode;
2424

25-
/** The cases under {@code test-cases-java28}, as {@link FormatterServiceImplTest} runs those of JDK 21. */
25+
/** {@link FormatterServiceImplTest} on JDK 28 and later, with the cases of JDK 21, 25 and 28. */
2626
@EnabledForJreRange(min = JRE.JAVA_28)
2727
@Execution(ExecutionMode.CONCURRENT)
2828
final class FormatterServiceImplJava28Test {
2929
@TestFactory
3030
List<DynamicTest> replacesTheChangedLinesAsTheCommandLineDoes() throws Exception {
31-
return FormatterServiceImplTest.changedLinesIn("test-cases-java28");
31+
return FormatterServiceImplTest.changedLinesIn("test-cases-java21", "test-cases-java25", "test-cases-java28");
3232
}
3333
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterServiceImplTest.java‎

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,35 @@
2929
import java.util.ArrayList;
3030
import java.util.List;
3131
import org.junit.jupiter.api.DynamicTest;
32-
import org.junit.jupiter.api.TestFactory;
33-
import org.junit.jupiter.api.parallel.Execution;
34-
import org.junit.jupiter.api.parallel.ExecutionMode;
3532

3633
/**
3734
* The service that formats in the build's own JVM, as {@code formatDiff} does without the native binary, against the
3835
* command line, which the bootstrapping and native services run: for each case, the lines that formatting changes,
39-
* taken as a range, get the same replacements from both.
36+
* taken as a range, get the same replacements from both. Each JDK has a class that runs the case folders it can parse,
37+
* such as {@link FormatterServiceImplJava21Test}.
4038
*/
41-
@Execution(ExecutionMode.CONCURRENT)
4239
final class FormatterServiceImplTest {
4340
private static final FormatterService SERVICE = new FormatterServiceImpl();
4441
private static final ObjectMapper MAPPER =
4542
JsonMapper.builder().addModule(new GuavaModule()).build();
4643

47-
@TestFactory
48-
List<DynamicTest> replacesTheChangedLinesAsTheCommandLineDoes() throws Exception {
49-
return changedLinesIn("test-cases-java21");
50-
}
51-
52-
/** The tests of the case files under {@code folder} on the test classpath. */
53-
static List<DynamicTest> changedLinesIn(String folder) throws Exception {
54-
var root = CaseFile.folder(folder);
44+
/** The tests of the case files under {@code folders} on the test classpath. */
45+
static List<DynamicTest> changedLinesIn(String... folders) throws Exception {
5546
var tests = new ArrayList<DynamicTest>();
5647

57-
for (var path : CaseFile.pathsIn(root)) {
58-
tests.add(DynamicTest.dynamicTest(path, () -> {
59-
var testCase = CaseFile.parse(path, Files.readString(root.resolve(path)));
60-
var lines = testCase.changedLines();
48+
for (var folder : folders) {
49+
var root = CaseFile.folder(folder);
50+
51+
for (var path : CaseFile.pathsIn(root)) {
52+
tests.add(DynamicTest.dynamicTest(path, () -> {
53+
var testCase = CaseFile.parse(path, Files.readString(root.resolve(path)));
54+
var lines = testCase.changedLines();
6155

62-
assertThat(SERVICE.getFormatReplacements(testCase.before(), List.of(lines)))
63-
.as(() -> folder + "/" + path + ", characters " + lines)
64-
.isEqualTo(commandLine(testCase.before(), lines));
65-
}));
56+
assertThat(SERVICE.getFormatReplacements(testCase.before(), List.of(lines)))
57+
.as(() -> folder + "/" + path + ", characters " + lines)
58+
.isEqualTo(commandLine(testCase.before(), lines));
59+
}));
60+
}
6661
}
6762

6863
return tests;

0 commit comments

Comments
 (0)