Skip to content

Commit 71c3d64

Browse files
committed
Forbid pre-17 JREs in execution condition annotations
1 parent ab97b53 commit 71c3d64

File tree

14 files changed

+66
-72
lines changed

14 files changed

+66
-72
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ repository on GitHub.
6565

6666
* The `JRE` enum constants for `JAVA_8` to `JAVA_16` have been deprecated because they can
6767
no longer be used at runtime since `JAVA_17` is the new baseline.
68+
* `@EnabledForJreRange` and `@DisabledForJreRange` now use `JAVA_17` as their default
69+
`min` value.
70+
* `@EnabledOnJre`, `@DisabledOnJre`, `@EnabledForJreRange`, and `@DisabledForJreRange` now
71+
fail if a JRE version less than 17 is specified.
6872

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

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ protected final IntStream validatedVersions(JRE[] jres, int[] versions) {
4848
() -> "JRE.UNDEFINED is not supported in @" + this.annotationName);
4949
return jre.version();
5050
}), //
51-
Arrays.stream(versions).map(version -> {
52-
Preconditions.condition(version >= JRE.MINIMUM_VERSION,
53-
() -> String.format("Version [%d] in @%s must be greater than or equal to %d", version,
54-
this.annotationName, JRE.MINIMUM_VERSION));
55-
return version;
56-
})//
51+
Arrays.stream(versions).peek(version -> Preconditions.condition(version >= JRE.MINIMUM_VERSION,
52+
() -> String.format("Version [%d] in @%s must be greater than or equal to %d", version,
53+
this.annotationName, JRE.MINIMUM_VERSION)))//
5754
).distinct();
5855
}
5956

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

+3-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int
5858
// Now that we have checked the basic preconditions, we need to ensure that we are
5959
// using valid JRE enum constants.
6060
if (!minJreSet) {
61-
minJre = minJre();
61+
minJre = JRE.JAVA_17;
6262
}
6363
if (!maxJreSet) {
6464
maxJre = JRE.OTHER;
@@ -71,18 +71,13 @@ protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int
7171
Preconditions.condition((min != JRE.MINIMUM_VERSION || max != Integer.MAX_VALUE),
7272
() -> "You must declare a non-default value for the minimum or maximum value in @" + this.annotationName);
7373
Preconditions.condition(min >= JRE.MINIMUM_VERSION,
74-
() -> String.format("@%s's minimum value [%d] must greater than or equal to %d", this.annotationName, min,
75-
JRE.MINIMUM_VERSION));
74+
() -> String.format("@%s's minimum value [%d] must be greater than or equal to %d", this.annotationName,
75+
min, JRE.MINIMUM_VERSION));
7676
Preconditions.condition(min <= max,
7777
() -> String.format("@%s's minimum value [%d] must be less than or equal to its maximum value [%d]",
7878
this.annotationName, min, max));
7979

8080
return JRE.isCurrentVersionWithinRange(min, max);
8181
}
8282

83-
@SuppressWarnings("removal")
84-
private static JRE minJre() {
85-
return JRE.JAVA_8;
86-
}
87-
8883
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
* {@link #minVersion() minVersion} instead.
9797
*
9898
* <p>Defaults to {@link JRE#UNDEFINED UNDEFINED}, which will be interpreted
99-
* as {@link JRE#JAVA_8 JAVA_8} if the {@link #minVersion() minVersion} is
99+
* as {@link JRE#JAVA_17 JAVA_17} if the {@link #minVersion() minVersion} is
100100
* not set.
101101
*
102102
* @see JRE

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
* {@link #minVersion() minVersion} instead.
9797
*
9898
* <p>Defaults to {@link JRE#UNDEFINED UNDEFINED}, which will be interpreted
99-
* as {@link JRE#JAVA_8 JAVA_8} if the {@link #minVersion() minVersion} is
99+
* as {@link JRE#JAVA_17 JAVA_17} if the {@link #minVersion() minVersion} is
100100
* not set.
101101
*
102102
* @see JRE

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public enum JRE {
8888

8989
static final int UNDEFINED_VERSION = -1;
9090

91-
static final int MINIMUM_VERSION = ${jres.getFirst().getVersion()};
91+
static final int MINIMUM_VERSION = ${minRuntimeVersion};
9292

9393
private static final int CURRENT_VERSION = Runtime.version().feature();
9494

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

+2-2
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 version7() {
77+
void version16() {
7878
assertThatExceptionOfType(PreconditionViolationException.class)//
7979
.isThrownBy(this::evaluateCondition)//
80-
.withMessage("Version [7] in @DisabledOnJre must be greater than or equal to 8");
80+
.withMessage("Version [16] in @DisabledOnJre must be greater than or equal to 17");
8181
}
8282

8383
/**

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class DisabledOnJreIntegrationTests {
5050

5151
@Test
5252
@Disabled("Only used in a unit test via reflection")
53-
@DisabledOnJre(versions = 7)
54-
void version7() {
53+
@DisabledOnJre(versions = 16)
54+
void version16() {
5555
}
5656

5757
@Test

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ class EnabledOnJreConditionTests extends AbstractExecutionConditionTests {
7171
}
7272

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

8383
/**

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class EnabledOnJreIntegrationTests {
4949

5050
@Test
5151
@Disabled("Only used in a unit test via reflection")
52-
@EnabledOnJre(versions = 7)
53-
void version7() {
52+
@EnabledOnJre(versions = 16)
53+
void version16() {
5454
}
5555

5656
@Test

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ void effectiveVersionDefaultValues() {
8080
}
8181

8282
/**
83-
* @see DisabledForJreRangeIntegrationTests#min8()
83+
* @see DisabledForJreRangeIntegrationTests#min17()
8484
*/
8585
@Test
86-
void min8() {
86+
void min17() {
8787
defaultValues();
8888
}
8989

9090
/**
91-
* @see DisabledForJreRangeIntegrationTests#minVersion8()
91+
* @see DisabledForJreRangeIntegrationTests#minVersion17()
9292
*/
9393
@Test
94-
void minVersion8() {
94+
void minVersion17() {
9595
defaultValues();
9696
}
9797

@@ -112,23 +112,23 @@ void maxVersionMaxInteger() {
112112
}
113113

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

124124
/**
125-
* @see DisabledForJreRangeIntegrationTests#maxVersion7()
125+
* @see DisabledForJreRangeIntegrationTests#maxVersion16()
126126
*/
127127
@Test
128-
void maxVersion7() {
128+
void maxVersion16() {
129129
assertThatExceptionOfType(PreconditionViolationException.class)//
130130
.isThrownBy(this::evaluateCondition)//
131-
.withMessage("@DisabledForJreRange's maxVersion [7] must be greater than or equal to 8");
131+
.withMessage("@DisabledForJreRange's maxVersion [16] must be greater than or equal to 17");
132132
}
133133

134134
/**

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,30 @@ void defaultValues() {
4747
@SuppressWarnings("removal")
4848
@Test
4949
@Disabled("Only used in a unit test via reflection")
50-
@DisabledForJreRange(min = JRE.JAVA_8, max = OTHER)
50+
@DisabledForJreRange(min = JRE.JAVA_17, max = OTHER)
5151
void effectiveJreDefaultValues() {
5252
fail("should result in a configuration exception");
5353
}
5454

5555
@Test
5656
@Disabled("Only used in a unit test via reflection")
57-
@DisabledForJreRange(minVersion = 8, maxVersion = Integer.MAX_VALUE)
57+
@DisabledForJreRange(minVersion = 17, maxVersion = Integer.MAX_VALUE)
5858
void effectiveVersionDefaultValues() {
5959
fail("should result in a configuration exception");
6060
}
6161

6262
@SuppressWarnings("removal")
6363
@Test
6464
@Disabled("Only used in a unit test via reflection")
65-
@DisabledForJreRange(min = JRE.JAVA_8)
66-
void min8() {
65+
@DisabledForJreRange(min = JAVA_17)
66+
void min17() {
6767
fail("should result in a configuration exception");
6868
}
6969

7070
@Test
7171
@Disabled("Only used in a unit test via reflection")
72-
@DisabledForJreRange(minVersion = 8)
73-
void minVersion8() {
72+
@DisabledForJreRange(minVersion = 17)
73+
void minVersion17() {
7474
fail("should result in a configuration exception");
7575
}
7676

@@ -90,15 +90,15 @@ void maxVersionMaxInteger() {
9090

9191
@Test
9292
@Disabled("Only used in a unit test via reflection")
93-
@DisabledForJreRange(minVersion = 7)
94-
void minVersion7() {
93+
@DisabledForJreRange(minVersion = 16)
94+
void minVersion16() {
9595
fail("should result in a configuration exception");
9696
}
9797

9898
@Test
9999
@Disabled("Only used in a unit test via reflection")
100-
@DisabledForJreRange(maxVersion = 7)
101-
void maxVersion7() {
100+
@DisabledForJreRange(maxVersion = 16)
101+
void maxVersion16() {
102102
fail("should result in a configuration exception");
103103
}
104104

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ void effectiveVersionDefaultValues() {
8686
}
8787

8888
/**
89-
* @see EnabledForJreRangeIntegrationTests#min8()
89+
* @see EnabledForJreRangeIntegrationTests#min17()
9090
*/
9191
@Test
92-
void min8() {
92+
void min17() {
9393
defaultValues();
9494
}
9595

9696
/**
97-
* @see EnabledForJreRangeIntegrationTests#minVersion8()
97+
* @see EnabledForJreRangeIntegrationTests#minVersion17()
9898
*/
9999
@Test
100-
void minVersion8() {
100+
void minVersion17() {
101101
defaultValues();
102102
}
103103

@@ -118,23 +118,23 @@ void maxVersionMaxInteger() {
118118
}
119119

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

130130
/**
131-
* @see EnabledForJreRangeIntegrationTests#maxVersion7()
131+
* @see EnabledForJreRangeIntegrationTests#maxVersion16()
132132
*/
133133
@Test
134-
void maxVersion7() {
134+
void maxVersion16() {
135135
assertThatExceptionOfType(PreconditionViolationException.class)//
136136
.isThrownBy(this::evaluateCondition)//
137-
.withMessage("@EnabledForJreRange's maxVersion [7] must be greater than or equal to 8");
137+
.withMessage("@EnabledForJreRange's maxVersion [16] must be greater than or equal to 17");
138138
}
139139

140140
/**
@@ -303,10 +303,10 @@ void minVersion20MaxVersion21() {
303303
}
304304

305305
/**
306-
* @see EnabledForJreRangeIntegrationTests#minVersion17MaxVersionMaxInteger()
306+
* @see EnabledForJreRangeIntegrationTests#minVersion21MaxVersionMaxInteger()
307307
*/
308308
@Test
309-
void minVersion17MaxVersionMaxInteger() {
309+
void minVersion21MaxVersionMaxInteger() {
310310
evaluateCondition();
311311
assertEnabledOnCurrentJreIf(onJava17() || onJava18() || onJava19() || onJava20() || onJava21() || onJava22()
312312
|| onJava23() || onJava24() || onJava25());

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

+12-14
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,31 @@ void defaultValues() {
5151
fail("should result in a configuration exception");
5252
}
5353

54-
@SuppressWarnings("removal")
5554
@Test
5655
@Disabled("Only used in a unit test via reflection")
57-
@EnabledForJreRange(min = JRE.JAVA_8, max = OTHER)
56+
@EnabledForJreRange(min = JAVA_17, max = OTHER)
5857
void effectiveJreDefaultValues() {
5958
fail("should result in a configuration exception");
6059
}
6160

6261
@Test
6362
@Disabled("Only used in a unit test via reflection")
64-
@EnabledForJreRange(minVersion = 8, maxVersion = Integer.MAX_VALUE)
63+
@EnabledForJreRange(minVersion = 17, maxVersion = Integer.MAX_VALUE)
6564
void effectiveVersionDefaultValues() {
6665
fail("should result in a configuration exception");
6766
}
6867

69-
@SuppressWarnings("removal")
7068
@Test
7169
@Disabled("Only used in a unit test via reflection")
72-
@EnabledForJreRange(min = JRE.JAVA_8)
73-
void min8() {
70+
@EnabledForJreRange(min = JAVA_17)
71+
void min17() {
7472
fail("should result in a configuration exception");
7573
}
7674

7775
@Test
7876
@Disabled("Only used in a unit test via reflection")
79-
@EnabledForJreRange(minVersion = 8)
80-
void minVersion8() {
77+
@EnabledForJreRange(minVersion = 17)
78+
void minVersion17() {
8179
fail("should result in a configuration exception");
8280
}
8381

@@ -97,15 +95,15 @@ void maxVersionMaxInteger() {
9795

9896
@Test
9997
@Disabled("Only used in a unit test via reflection")
100-
@EnabledForJreRange(minVersion = 7)
101-
void minVersion7() {
98+
@EnabledForJreRange(minVersion = 16)
99+
void minVersion16() {
102100
fail("should result in a configuration exception");
103101
}
104102

105103
@Test
106104
@Disabled("Only used in a unit test via reflection")
107-
@EnabledForJreRange(maxVersion = 7)
108-
void maxVersion7() {
105+
@EnabledForJreRange(maxVersion = 16)
106+
void maxVersion16() {
109107
fail("should result in a configuration exception");
110108
}
111109

@@ -241,8 +239,8 @@ void minVersion20MaxVersion21() {
241239
}
242240

243241
@Test
244-
@EnabledForJreRange(minVersion = 17, maxVersion = Integer.MAX_VALUE)
245-
void minVersion17MaxVersionMaxInteger() {
242+
@EnabledForJreRange(minVersion = 21, maxVersion = Integer.MAX_VALUE)
243+
void minVersion21MaxVersionMaxInteger() {
246244
assertTrue(onKnownVersion());
247245
assertTrue(JRE.currentVersionNumber() >= 17);
248246
}

0 commit comments

Comments
 (0)