Skip to content

Commit b86ae66

Browse files
committed
Merge remote-tracking branch 'origin/abashev/JDK-split-tests' into abashev/Range-reflow-in-process
# Conflicts: # open-java-format/src/test/java/com/palantir/javaformat/java/FormatterCasesTest.java
2 parents 2de503e + 4039677 commit b86ae66

4 files changed

Lines changed: 64 additions & 37 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+
/** The cases on JDK 21 to 24, which parse the syntax of JDK 21. */
26+
@EnabledForJreRange(max = JRE.JAVA_24)
27+
@Execution(ExecutionMode.CONCURRENT)
28+
final class FormatterCasesJava21Test {
29+
@TestFactory
30+
List<DynamicTest> cases() throws Exception {
31+
return FormatterCasesTest.casesIn("test-cases-java21");
32+
}
33+
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterCasesJava25Test.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 FormatterCasesTest} runs those of JDK 21, for syntax of JDK 25. */
26-
@EnabledForJreRange(min = JRE.JAVA_25)
25+
/** The cases on JDK 25 to 27: those of JDK 21, and those for the syntax of JDK 25. */
26+
@EnabledForJreRange(min = JRE.JAVA_25, max = JRE.JAVA_27)
2727
@Execution(ExecutionMode.CONCURRENT)
2828
final class FormatterCasesJava25Test {
2929
@TestFactory
3030
List<DynamicTest> cases() throws Exception {
31-
return FormatterCasesTest.casesIn("test-cases-java25");
31+
return FormatterCasesTest.casesIn("test-cases-java21", "test-cases-java25");
3232
}
3333
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterCasesJava28Test.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 FormatterCasesTest} runs those of JDK 21, for syntax of JDK 28. */
25+
/** The cases on JDK 28 and later: those of JDK 21 and 25, and those for the syntax of JDK 28. */
2626
@EnabledForJreRange(min = JRE.JAVA_28)
2727
@Execution(ExecutionMode.CONCURRENT)
2828
final class FormatterCasesJava28Test {
2929
@TestFactory
3030
List<DynamicTest> cases() throws Exception {
31-
return FormatterCasesTest.casesIn("test-cases-java28");
31+
return FormatterCasesTest.casesIn("test-cases-java21", "test-cases-java25", "test-cases-java28");
3232
}
3333
}

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

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,46 @@
2121
import java.util.ArrayList;
2222
import java.util.List;
2323
import org.junit.jupiter.api.DynamicTest;
24-
import org.junit.jupiter.api.TestFactory;
25-
import org.junit.jupiter.api.parallel.Execution;
26-
import org.junit.jupiter.api.parallel.ExecutionMode;
2724

2825
/**
29-
* One test for each {@link CaseFile} under {@code test-cases-java21} on the test classpath: formatting the before block
30-
* gives the after block, and formatting that again changes nothing. Adding a case is adding a file. Cases that need a
31-
* newer JDK are in a folder of that JDK, run by a class of their own, such as {@link FormatterCasesJava25Test}.
26+
* One test for each {@link CaseFile} in the given folders on the test classpath: formatting the before block gives the
27+
* after block, and formatting that again changes nothing. Adding a case is adding a file. The cases are in a folder of
28+
* the JDK they need, and each JDK has a class that runs the folders it can parse, such as
29+
* {@link FormatterCasesJava21Test}.
3230
*/
33-
@Execution(ExecutionMode.CONCURRENT)
3431
final class FormatterCasesTest {
3532
private static final Formatter FORMATTER = Formatter.createFormatter(
3633
JavaFormatterOptions.builder().style(Style.OJF).build());
3734

38-
@TestFactory
39-
List<DynamicTest> cases() throws Exception {
40-
return casesIn("test-cases-java21");
41-
}
42-
43-
/** The tests of the case files under {@code folder} on the test classpath. */
44-
static List<DynamicTest> casesIn(String folder) throws Exception {
45-
var root = CaseFile.folder(folder);
46-
var paths = CaseFile.pathsIn(root);
35+
/** The tests of the case files under {@code folders} on the test classpath. */
36+
static List<DynamicTest> casesIn(String... folders) throws Exception {
37+
var tests = new ArrayList<DynamicTest>();
4738

48-
// A wrong folder or a resource filter would otherwise pass with no tests at all.
49-
assertThat(paths).as("the case files under %s", root).isNotEmpty();
39+
for (var folder : folders) {
40+
var root = CaseFile.folder(folder);
41+
var paths = CaseFile.pathsIn(root);
5042

51-
var tests = new ArrayList<DynamicTest>();
43+
// A wrong folder or a resource filter would otherwise pass with no tests at all.
44+
assertThat(paths).as("the case files under %s", root).isNotEmpty();
5245

53-
for (var path : paths) {
54-
var name = path.substring(0, path.length() - CaseFile.EXTENSION.length());
46+
for (var path : paths) {
47+
var name = path.substring(0, path.length() - CaseFile.EXTENSION.length());
5548

56-
tests.add(DynamicTest.dynamicTest(name, () -> {
57-
var testCase = CaseFile.parse(path, Files.readString(root.resolve(path)));
58-
var once = FORMATTER.formatSourceAndFixImports(testCase.before());
49+
tests.add(DynamicTest.dynamicTest(name, () -> {
50+
var testCase = CaseFile.parse(path, Files.readString(root.resolve(path)));
51+
var once = FORMATTER.formatSourceAndFixImports(testCase.before());
5952

60-
assertThat(once)
61-
.as(() -> folder + "/" + path + ", first run, " + testCase.firstDifference(once))
62-
.isEqualTo(testCase.after());
53+
assertThat(once)
54+
.as(() -> folder + "/" + path + ", first run, " + testCase.firstDifference(once))
55+
.isEqualTo(testCase.after());
6356

64-
var twice = FORMATTER.formatSourceAndFixImports(once);
57+
var twice = FORMATTER.formatSourceAndFixImports(once);
6558

66-
assertThat(twice)
67-
.as(() -> folder + "/" + path + ", second run, " + testCase.firstDifference(twice))
68-
.isEqualTo(once);
69-
}));
59+
assertThat(twice)
60+
.as(() -> folder + "/" + path + ", second run, " + testCase.firstDifference(twice))
61+
.isEqualTo(once);
62+
}));
63+
}
7064
}
7165

7266
return tests;

0 commit comments

Comments
 (0)