Skip to content

Commit 01fc6dc

Browse files
committed
Run the value-class tests from JDK 28, and sort shuffled module imports
The value classes of JEP 401 are a preview of JDK 28, and its early-access builds have the `value` modifier, so their tests go by the version, as the module imports do, rather than by a condition on Modifier.VALUE: the formatting one becomes a case in test-cases-java28, run by FormatterCasesJava28Test, and the ModifierOrderer one moves to ModifierOrdererJava28Test, both from JDK 28. The module-import case had its imports already in order; its input now has the ordinary import first and the module imports reversed.
1 parent 2119e2f commit 01fc6dc

5 files changed

Lines changed: 96 additions & 82 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 under {@code test-cases-java28}, as {@link FormatterCasesTest} runs those of JDK 21, for syntax of JDK 28. */
26+
@EnabledForJreRange(min = JRE.JAVA_28)
27+
@Execution(ExecutionMode.CONCURRENT)
28+
final class FormatterCasesJava28Test {
29+
@TestFactory
30+
List<DynamicTest> cases() throws Exception {
31+
return FormatterCasesTest.casesIn("test-cases-java28");
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 static com.google.common.truth.Truth.assertThat;
18+
19+
import org.junit.jupiter.api.Test;
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 ModifierOrderer} on the {@code value} modifier of value classes, a preview of JDK 28. */
26+
@EnabledForJreRange(min = JRE.JAVA_28)
27+
@Execution(ExecutionMode.CONCURRENT)
28+
final class ModifierOrdererJava28Test {
29+
@Test
30+
void valueClass() throws FormatterException {
31+
assertThat(ModifierOrderer.reorderModifiers("value final public").getText())
32+
.isEqualTo("public final value");
33+
}
34+
}

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

Lines changed: 0 additions & 78 deletions
This file was deleted.

‎open-java-format/src/test/resources/test-cases-java25/moduleImports.case‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# Module imports (JEP 511) before an ordinary import.
1+
# Module imports (JEP 511) are sorted before the ordinary imports, with a blank line between them.
22
----------
3-
import module java.base;
4-
import module java.sql;
5-
63
import java.util.List;
4+
import module java.sql;
5+
import module java.base;
76

87
class ModuleImport {
98
List<String> xs;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# The `value` modifier of value classes and records (JEP 401, a preview of JDK 28) goes after the other
2+
# modifiers (#131).
3+
----------
4+
value final public class PointValueClass {
5+
final int x;
6+
final int y;
7+
8+
PointValueClass(int x, int y) {
9+
this.x = x;
10+
this.y = y;
11+
}
12+
}
13+
14+
value public record PointValueRecord(int x, int y) {}
15+
----------
16+
public final value class PointValueClass {
17+
final int x;
18+
final int y;
19+
20+
PointValueClass(int x, int y) {
21+
this.x = x;
22+
this.y = y;
23+
}
24+
}
25+
26+
public value record PointValueRecord(int x, int y) {}

0 commit comments

Comments
 (0)