Skip to content

Commit 415c4fe

Browse files
committed
Allow JREs < 17 again
1 parent 1c7a15c commit 415c4fe

File tree

12 files changed

+53
-58
lines changed

12 files changed

+53
-58
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-6.0.0-M1.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ repository on GitHub.
6767
no longer be used at runtime since `JAVA_17` is the new baseline.
6868
* `@EnabledForJreRange` and `@DisabledForJreRange` now use `JAVA_17` as their default
6969
`min` value.
70-
* `@EnabledOnJre`, `@DisabledOnJre`, `@EnabledForJreRange`, and `@DisabledForJreRange` now
71-
fail if a JRE version less than 17 is specified.
7270

7371
[[release-notes-6.0.0-M1-junit-jupiter-new-features-and-improvements]]
7472
==== New Features and Improvements

gradle/plugins/code-generator/src/main/kotlin/junitbuild/generator/GenerateJreRelatedSourceCode.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ abstract class GenerateJreRelatedSourceCode : DefaultTask() {
6161
val supportedJres = jres.filter { it.version >= minRuntimeVersion }
6262
val params = mapOf(
6363
"minRuntimeVersion" to minRuntimeVersion,
64-
"jres" to jres,
64+
"allJres" to jres,
6565
"supportedJres" to supportedJres,
6666
"supportedJresSortedByStringValue" to supportedJres.sortedBy { it.version.toString() },
6767
"licenseHeader" to licenseHeaderFile.asFile.get().readText()

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreRangeCondition.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
*/
2727
abstract class AbstractJreRangeCondition<A extends Annotation> extends BooleanExecutionCondition<A> {
2828

29+
private static final JRE DEFAULT_MINIMUM_JRE = JRE.JAVA_17;
30+
private static final JRE DEFAULT_MAXIMUM_JRE = JRE.OTHER;
31+
2932
private final String annotationName;
3033

3134
AbstractJreRangeCondition(Class<A> annotationType, Function<A, String> customDisabledReason) {
@@ -58,17 +61,17 @@ protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int
5861
// Now that we have checked the basic preconditions, we need to ensure that we are
5962
// using valid JRE enum constants.
6063
if (!minJreSet) {
61-
minJre = JRE.JAVA_17;
64+
minJre = DEFAULT_MINIMUM_JRE;
6265
}
6366
if (!maxJreSet) {
64-
maxJre = JRE.OTHER;
67+
maxJre = DEFAULT_MAXIMUM_JRE;
6568
}
6669

6770
int min = (minVersionSet ? minVersion : minJre.version());
6871
int max = (maxVersionSet ? maxVersion : maxJre.version());
6972

7073
// Finally, we need to validate the effective minimum and maximum values.
71-
Preconditions.condition((min != JRE.MINIMUM_VERSION || max != Integer.MAX_VALUE),
74+
Preconditions.condition((min != DEFAULT_MINIMUM_JRE.version() || max != DEFAULT_MAXIMUM_JRE.version()),
7275
() -> "You must declare a non-default value for the minimum or maximum value in @" + this.annotationName);
7376
Preconditions.condition(min <= max,
7477
() -> String.format("@%s's minimum value [%d] must be less than or equal to its maximum value [%d]",

junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@import junitbuild.generator.model.JRE
44

55
@param int minRuntimeVersion
6-
@param List<JRE> jres
6+
@param List<JRE> allJres
77
@param String licenseHeader
88
${licenseHeader}
99
package org.junit.jupiter.api.condition;
@@ -22,7 +22,7 @@ import org.apiguardian.api.API;
2222
* {@linkplain #isCurrentVersion current JRE version}.
2323
*
2424
* @since 5.1
25-
@for(JRE jre : jres)<%--
25+
@for(JRE jre : allJres)<%--
2626
--%> * @see #JAVA_${jre.getVersion()}
2727
@endfor<%--
2828
--%> * @see #OTHER
@@ -46,7 +46,7 @@ public enum JRE {
4646
*/
4747
@API(status = EXPERIMENTAL, since = "5.12")
4848
UNDEFINED(-1),
49-
@for(var jre : jres)
49+
@for(var jre : allJres)
5050
/**
5151
* Java ${jre.getVersion()}.
5252
@if(jre.getSince() != null || jre.getVersion() < minRuntimeVersion)<%--
@@ -69,7 +69,7 @@ public enum JRE {
6969
@endfor
7070
/**
7171
* A JRE version other than <%--
72-
--%>@for(var jre : ForSupport.of(jres))<%--
72+
--%>@for(var jre : ForSupport.of(allJres))<%--
7373
--%>@if(jre.isLast())or @endif<%--
7474
--%>{@link #JAVA_${jre.get().getVersion()}}<%--
7575
--%>@if(jre.isLast()).@else,@endif<%--
@@ -85,7 +85,7 @@ public enum JRE {
8585

8686
static final int UNDEFINED_VERSION = -1;
8787

88-
static final int MINIMUM_VERSION = ${minRuntimeVersion};
88+
static final int MINIMUM_VERSION = ${allJres.getFirst().getVersion()};
8989

9090
private static final int CURRENT_VERSION = Runtime.version().feature();
9191

@@ -148,7 +148,7 @@ public enum JRE {
148148
@API(status = STABLE, since = "5.12")
149149
public static JRE currentJre() {
150150
return switch (CURRENT_VERSION) {<%--
151-
--%>@for(var jre : jres)
151+
--%>@for(var jre : allJres)
152152
case ${jre.getVersion()} -> JAVA_${jre.getVersion()};<%--
153153
--%>@endfor
154154
default -> OTHER;

jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreConditionTests.java.jte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ class DisabledOnJreConditionTests extends AbstractExecutionConditionTests {
7474
* @see DisabledOnJreIntegrationTests#version7()
7575
*/
7676
@Test
77-
void version16() {
77+
void version7() {
7878
assertThatExceptionOfType(PreconditionViolationException.class)//
7979
.isThrownBy(this::evaluateCondition)//
80-
.withMessage("Version [16] in @DisabledOnJre must be greater than or equal to 17");
80+
.withMessage("Version [7] in @DisabledOnJre must be greater than or equal to 8");
8181
}
8282

8383
/**

jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreIntegrationTests.java.jte

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import java.util.List
22
@import junitbuild.generator.model.JRE
33

4+
@param List<JRE> allJres
45
@param List<JRE> supportedJres
56
@param List<JRE> supportedJresSortedByStringValue
67
@param String licenseHeader
@@ -11,11 +12,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
1112
import static org.junit.jupiter.api.Assertions.assertTrue;
1213
import static org.junit.jupiter.api.Assertions.fail;
1314
@for(var jre : supportedJresSortedByStringValue)<%--
14-
--%>import static org.junit.jupiter.api.condition.JRE.JAVA_${jre.getVersion()};
15-
@endfor<%--
16-
--%>import static org.junit.jupiter.api.condition.JRE.OTHER;
17-
import static org.junit.jupiter.api.condition.JRE.UNDEFINED;
18-
@for(var jre : supportedJresSortedByStringValue)<%--
1915
--%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()};
2016
@endfor<%--
2117
--%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
@@ -44,29 +40,30 @@ class DisabledOnJreIntegrationTests {
4440

4541
@Test
4642
@Disabled("Only used in a unit test via reflection")
47-
@DisabledOnJre(UNDEFINED)
43+
@DisabledOnJre(JRE.UNDEFINED)
4844
void jreUndefined() {
4945
}
5046

5147
@Test
5248
@Disabled("Only used in a unit test via reflection")
53-
@DisabledOnJre(value = JAVA_17, versions = { 21, 16 })
54-
void version16() {
49+
@DisabledOnJre(value = JRE.JAVA_17, versions = { 21, 7 })
50+
void version7() {
5551
}
5652

53+
@SuppressWarnings("removal")
5754
@Test
5855
@DisabledOnJre(disabledReason = "Disabled on every JRE", value = { //
59-
@for(var jre : supportedJres)<%--
60-
--%> JAVA_${jre.getVersion()}, //
56+
@for(var jre : allJres)<%--
57+
--%> JRE.JAVA_${jre.getVersion()}, //
6158
@endfor<%--
62-
--%> OTHER //
59+
--%> JRE.OTHER //
6360
})
6461
void disabledOnAllJavaVersions() {
6562
fail("should be disabled");
6663
}
6764
@for(var jre : supportedJres)
6865
@Test
69-
@DisabledOnJre(JAVA_${jre.getVersion()})
66+
@DisabledOnJre(JRE.JAVA_${jre.getVersion()})
7067
void jre${jre.getVersion()}() {
7168
assertFalse(onJava${jre.getVersion()}());
7269
}
@@ -79,7 +76,7 @@ class DisabledOnJreIntegrationTests {
7976
}
8077
@endfor
8178
@Test
82-
@DisabledOnJre(OTHER)
79+
@DisabledOnJre(JRE.OTHER)
8380
void other() {
8481
assertTrue(onKnownVersion());
8582
}

jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreConditionTests.java.jte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ class EnabledOnJreConditionTests extends AbstractExecutionConditionTests {
7171
}
7272

7373
/**
74-
* @see EnabledOnJreIntegrationTests#version16()
74+
* @see EnabledOnJreIntegrationTests#version7()
7575
*/
7676
@Test
77-
void version16() {
77+
void version7() {
7878
assertThatExceptionOfType(PreconditionViolationException.class)//
7979
.isThrownBy(this::evaluateCondition)//
80-
.withMessage("Version [16] in @EnabledOnJre must be greater than or equal to 17");
80+
.withMessage("Version [7] in @EnabledOnJre must be greater than or equal to 8");
8181
}
8282

8383
/**

jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreIntegrationTests.java.jte

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import java.util.List
22
@import junitbuild.generator.model.JRE
33

4+
@param List<JRE> allJres
45
@param List<JRE> supportedJres
56
@param List<JRE> supportedJresSortedByStringValue
67
@param String licenseHeader
@@ -10,11 +11,6 @@ package org.junit.jupiter.api.condition;
1011
import static org.junit.jupiter.api.Assertions.assertFalse;
1112
import static org.junit.jupiter.api.Assertions.assertTrue;
1213
@for(var jre : supportedJresSortedByStringValue)<%--
13-
--%>import static org.junit.jupiter.api.condition.JRE.JAVA_${jre.getVersion()};
14-
@endfor<%--
15-
--%>import static org.junit.jupiter.api.condition.JRE.OTHER;
16-
import static org.junit.jupiter.api.condition.JRE.UNDEFINED;
17-
@for(var jre : supportedJresSortedByStringValue)<%--
1814
--%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()};
1915
@endfor<%--
2016
--%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
@@ -43,28 +39,29 @@ class EnabledOnJreIntegrationTests {
4339

4440
@Test
4541
@Disabled("Only used in a unit test via reflection")
46-
@EnabledOnJre(UNDEFINED)
42+
@EnabledOnJre(JRE.UNDEFINED)
4743
void jreUndefined() {
4844
}
4945

5046
@Test
5147
@Disabled("Only used in a unit test via reflection")
52-
@EnabledOnJre(value = JAVA_17, versions = { 21, 16 })
53-
void version16() {
48+
@EnabledOnJre(value = JRE.JAVA_17, versions = { 21, 7 })
49+
void version7() {
5450
}
5551

52+
@SuppressWarnings("removal")
5653
@Test
5754
@EnabledOnJre({ //
58-
@for(var jre : supportedJres)<%--
59-
--%> JAVA_${jre.getVersion()}, //
55+
@for(var jre : allJres)<%--
56+
--%> JRE.JAVA_${jre.getVersion()}, //
6057
@endfor<%--
61-
--%> OTHER //
58+
--%> JRE.OTHER //
6259
})
6360
void enabledOnAllJavaVersions() {
6461
}
6562
@for(var jre : supportedJres)
6663
@Test
67-
@EnabledOnJre(JAVA_${jre.getVersion()})
64+
@EnabledOnJre(JRE.JAVA_${jre.getVersion()})
6865
void jre${jre.getVersion()}() {
6966
assertTrue(onJava${jre.getVersion()}());
7067
}
@@ -77,7 +74,7 @@ class EnabledOnJreIntegrationTests {
7774
}
7875
@endfor
7976
@Test
80-
@EnabledOnJre(value = OTHER, disabledReason = "Disabled on almost every JRE")
77+
@EnabledOnJre(value = JRE.OTHER, disabledReason = "Disabled on almost every JRE")
8178
void other() {
8279
assertFalse(onKnownVersion());
8380
}

jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeConditionTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ void maxVersionMaxInteger() {
112112
}
113113

114114
/**
115-
* @see DisabledForJreRangeIntegrationTests#minVersion16()
115+
* @see DisabledForJreRangeIntegrationTests#minVersion7()
116116
*/
117117
@Test
118-
void minVersion16() {
118+
void minVersion7() {
119119
assertThatExceptionOfType(PreconditionViolationException.class)//
120120
.isThrownBy(this::evaluateCondition)//
121-
.withMessage("@DisabledForJreRange's minVersion [16] must be greater than or equal to 17");
121+
.withMessage("@DisabledForJreRange's minVersion [7] must be greater than or equal to 8");
122122
}
123123

124124
/**
@@ -128,7 +128,8 @@ void minVersion16() {
128128
void maxVersion16() {
129129
assertThatExceptionOfType(PreconditionViolationException.class)//
130130
.isThrownBy(this::evaluateCondition)//
131-
.withMessage("@DisabledForJreRange's maxVersion [16] must be greater than or equal to 17");
131+
.withMessage(
132+
"@DisabledForJreRange's minimum value [17] must be less than or equal to its maximum value [16]");
132133
}
133134

134135
/**

jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeIntegrationTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ void defaultValues() {
4444
fail("should result in a configuration exception");
4545
}
4646

47-
@SuppressWarnings("removal")
4847
@Test
4948
@Disabled("Only used in a unit test via reflection")
50-
@DisabledForJreRange(min = JRE.JAVA_17, max = OTHER)
49+
@DisabledForJreRange(min = JAVA_17, max = OTHER)
5150
void effectiveJreDefaultValues() {
5251
fail("should result in a configuration exception");
5352
}
@@ -59,7 +58,6 @@ void effectiveVersionDefaultValues() {
5958
fail("should result in a configuration exception");
6059
}
6160

62-
@SuppressWarnings("removal")
6361
@Test
6462
@Disabled("Only used in a unit test via reflection")
6563
@DisabledForJreRange(min = JAVA_17)
@@ -90,8 +88,8 @@ void maxVersionMaxInteger() {
9088

9189
@Test
9290
@Disabled("Only used in a unit test via reflection")
93-
@DisabledForJreRange(minVersion = 16)
94-
void minVersion16() {
91+
@DisabledForJreRange(minVersion = 7)
92+
void minVersion7() {
9593
fail("should result in a configuration exception");
9694
}
9795

jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeConditionTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ void maxVersionMaxInteger() {
118118
}
119119

120120
/**
121-
* @see EnabledForJreRangeIntegrationTests#minVersion16()
121+
* @see EnabledForJreRangeIntegrationTests#minVersion7()
122122
*/
123123
@Test
124-
void minVersion16() {
124+
void minVersion7() {
125125
assertThatExceptionOfType(PreconditionViolationException.class)//
126126
.isThrownBy(this::evaluateCondition)//
127-
.withMessage("@EnabledForJreRange's minVersion [16] must be greater than or equal to 17");
127+
.withMessage("@EnabledForJreRange's minVersion [7] must be greater than or equal to 8");
128128
}
129129

130130
/**
@@ -134,7 +134,8 @@ void minVersion16() {
134134
void maxVersion16() {
135135
assertThatExceptionOfType(PreconditionViolationException.class)//
136136
.isThrownBy(this::evaluateCondition)//
137-
.withMessage("@EnabledForJreRange's maxVersion [16] must be greater than or equal to 17");
137+
.withMessage(
138+
"@EnabledForJreRange's minimum value [17] must be less than or equal to its maximum value [16]");
138139
}
139140

140141
/**

jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ void maxVersionMaxInteger() {
9595

9696
@Test
9797
@Disabled("Only used in a unit test via reflection")
98-
@EnabledForJreRange(minVersion = 16)
99-
void minVersion16() {
98+
@EnabledForJreRange(minVersion = 7)
99+
void minVersion7() {
100100
fail("should result in a configuration exception");
101101
}
102102

0 commit comments

Comments
 (0)