|
23 | 23 | import java.util.ArrayList; |
24 | 24 | import java.util.List; |
25 | 25 | import org.junit.jupiter.api.DynamicTest; |
26 | | -import org.junit.jupiter.api.TestFactory; |
27 | | -import org.junit.jupiter.api.parallel.Execution; |
28 | | -import org.junit.jupiter.api.parallel.ExecutionMode; |
29 | 26 |
|
30 | 27 | /** |
31 | | - * One test for each {@link CaseFile} under {@code test-cases} on the test classpath: formatting the before block gives |
32 | | - * the after block, and formatting that again changes nothing. Adding a case is adding a file. |
| 28 | + * One test for each {@link CaseFile} in the given folders on the test classpath: formatting the before block gives the |
| 29 | + * after block, and formatting that again changes nothing. Adding a case is adding a file. The cases are in a folder of |
| 30 | + * the JDK they need, and each JDK has a class that runs the folders it can parse, such as |
| 31 | + * {@link FormatterCasesJava21Test}. |
33 | 32 | */ |
34 | | -@Execution(ExecutionMode.CONCURRENT) |
35 | 33 | final class FormatterCasesTest { |
36 | | - private static final String CASES = "test-cases"; |
37 | | - |
38 | 34 | private static final Formatter FORMATTER = Formatter.createFormatter( |
39 | 35 | JavaFormatterOptions.builder().style(Style.OJF).build()); |
40 | 36 |
|
41 | | - @TestFactory |
42 | | - List<DynamicTest> cases() throws Exception { |
43 | | - var folder = requireNonNull( |
44 | | - FormatterCasesTest.class.getClassLoader().getResource(CASES), |
45 | | - "no " + CASES + " folder on the test classpath"); |
46 | | - var root = Path.of(folder.toURI()); |
47 | | - var paths = CaseFile.pathsIn(root); |
| 37 | + /** The tests of the case files under {@code folders} on the test classpath. */ |
| 38 | + static List<DynamicTest> casesIn(String... folders) throws Exception { |
| 39 | + var tests = new ArrayList<DynamicTest>(); |
48 | 40 |
|
49 | | - // A wrong folder or a resource filter would otherwise pass with no tests at all. |
50 | | - assertThat(paths).as("the case files under %s", root).isNotEmpty(); |
| 41 | + for (var folder : folders) { |
| 42 | + var url = requireNonNull( |
| 43 | + FormatterCasesTest.class.getClassLoader().getResource(folder), |
| 44 | + "no " + folder + " folder on the test classpath"); |
| 45 | + var root = Path.of(url.toURI()); |
| 46 | + var paths = CaseFile.pathsIn(root); |
51 | 47 |
|
52 | | - var tests = new ArrayList<DynamicTest>(); |
| 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(); |
53 | 50 |
|
54 | | - for (var path : paths) { |
55 | | - var name = path.substring(0, path.length() - CaseFile.EXTENSION.length()); |
| 51 | + for (var path : paths) { |
| 52 | + var name = path.substring(0, path.length() - CaseFile.EXTENSION.length()); |
56 | 53 |
|
57 | | - tests.add(DynamicTest.dynamicTest(name, () -> { |
58 | | - var testCase = CaseFile.parse(path, Files.readString(root.resolve(path))); |
59 | | - var once = FORMATTER.formatSourceAndFixImports(testCase.before()); |
| 54 | + tests.add(DynamicTest.dynamicTest(name, () -> { |
| 55 | + var testCase = CaseFile.parse(path, Files.readString(root.resolve(path))); |
| 56 | + var once = FORMATTER.formatSourceAndFixImports(testCase.before()); |
60 | 57 |
|
61 | | - assertThat(once) |
62 | | - .as(() -> CASES + "/" + path + ", first run, " + testCase.firstDifference(once)) |
63 | | - .isEqualTo(testCase.after()); |
| 58 | + assertThat(once) |
| 59 | + .as(() -> folder + "/" + path + ", first run, " + testCase.firstDifference(once)) |
| 60 | + .isEqualTo(testCase.after()); |
64 | 61 |
|
65 | | - var twice = FORMATTER.formatSourceAndFixImports(once); |
| 62 | + var twice = FORMATTER.formatSourceAndFixImports(once); |
66 | 63 |
|
67 | | - assertThat(twice) |
68 | | - .as(() -> CASES + "/" + path + ", second run, " + testCase.firstDifference(twice)) |
69 | | - .isEqualTo(once); |
70 | | - })); |
| 64 | + assertThat(twice) |
| 65 | + .as(() -> folder + "/" + path + ", second run, " + testCase.firstDifference(twice)) |
| 66 | + .isEqualTo(once); |
| 67 | + })); |
| 68 | + } |
71 | 69 | } |
72 | 70 |
|
73 | 71 | return tests; |
|
0 commit comments