|
21 | 21 | import java.util.ArrayList; |
22 | 22 | import java.util.List; |
23 | 23 | 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; |
27 | 24 |
|
28 | 25 | /** |
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}. |
32 | 30 | */ |
33 | | -@Execution(ExecutionMode.CONCURRENT) |
34 | 31 | final class FormatterCasesTest { |
35 | 32 | private static final Formatter FORMATTER = Formatter.createFormatter( |
36 | 33 | JavaFormatterOptions.builder().style(Style.OJF).build()); |
37 | 34 |
|
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>(); |
47 | 38 |
|
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); |
50 | 42 |
|
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(); |
52 | 45 |
|
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()); |
55 | 48 |
|
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()); |
59 | 52 |
|
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()); |
63 | 56 |
|
64 | | - var twice = FORMATTER.formatSourceAndFixImports(once); |
| 57 | + var twice = FORMATTER.formatSourceAndFixImports(once); |
65 | 58 |
|
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 | + } |
70 | 64 | } |
71 | 65 |
|
72 | 66 | return tests; |
|
0 commit comments