Skip to content

Commit f263410

Browse files
committed
Forbid pre-17 JREs in execution condition annotations
1 parent 95cfb7b commit f263410

File tree

14 files changed

+65
-146
lines changed

14 files changed

+65
-146
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

+4-11
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,16 @@ protected final IntStream validatedVersions(JRE[] jres, int[] versions) {
4242
Preconditions.condition(jres.length > 0 || versions.length > 0,
4343
() -> "You must declare at least one JRE or version in @" + this.annotationName);
4444

45-
var allVersions = IntStream.concat(//
45+
return IntStream.concat(//
4646
Arrays.stream(jres).mapToInt(jre -> {
4747
Preconditions.condition(jre != JRE.UNDEFINED,
4848
() -> "JRE.UNDEFINED is not supported in @" + this.annotationName);
4949
return jre.version();
5050
}), //
51-
Arrays.stream(versions).peek(version -> Preconditions.condition(version >= JRE.MINIMUM_DECLARED_VERSION,
51+
Arrays.stream(versions).peek(version -> Preconditions.condition(version >= JRE.MINIMUM_VERSION,
5252
() -> String.format("Version [%d] in @%s must be greater than or equal to %d", version,
53-
this.annotationName, JRE.MINIMUM_DECLARED_VERSION)))//
54-
).sorted().distinct().toArray();
55-
56-
var max = allVersions[allVersions.length - 1];
57-
Preconditions.condition(max >= JRE.MINIMUM_RUNTIME_VERSION,
58-
() -> String.format("Versions in @%s must contain at least one value greater than or equal to %d",
59-
this.annotationName, JRE.MINIMUM_RUNTIME_VERSION));
60-
61-
return IntStream.of(allVersions);
53+
this.annotationName, JRE.MINIMUM_VERSION)))//
54+
).distinct();
6255
}
6356

6457
}

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

+8-16
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int
4848
this.annotationName));
4949

5050
// Users must supply valid values for minVersion and maxVersion.
51-
Preconditions.condition(!minVersionSet || (minVersion >= JRE.MINIMUM_DECLARED_VERSION),
51+
Preconditions.condition(!minVersionSet || (minVersion >= JRE.MINIMUM_VERSION),
5252
() -> String.format("@%s's minVersion [%d] must be greater than or equal to %d", this.annotationName,
53-
minVersion, JRE.MINIMUM_DECLARED_VERSION));
54-
Preconditions.condition(!maxVersionSet || (maxVersion >= JRE.MINIMUM_DECLARED_VERSION),
53+
minVersion, JRE.MINIMUM_VERSION));
54+
Preconditions.condition(!maxVersionSet || (maxVersion >= JRE.MINIMUM_VERSION),
5555
() -> String.format("@%s's maxVersion [%d] must be greater than or equal to %d", this.annotationName,
56-
maxVersion, JRE.MINIMUM_DECLARED_VERSION));
56+
maxVersion, JRE.MINIMUM_VERSION));
5757

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;
@@ -68,24 +68,16 @@ protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int
6868
int max = (maxVersionSet ? maxVersion : maxJre.version());
6969

7070
// Finally, we need to validate the effective minimum and maximum values.
71-
Preconditions.condition((min != JRE.MINIMUM_DECLARED_VERSION || max != Integer.MAX_VALUE),
71+
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);
73-
Preconditions.condition(min >= JRE.MINIMUM_DECLARED_VERSION,
73+
Preconditions.condition(min >= JRE.MINIMUM_VERSION,
7474
() -> String.format("@%s's minimum value [%d] must be greater than or equal to %d", this.annotationName,
75-
min, JRE.MINIMUM_DECLARED_VERSION));
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));
79-
Preconditions.condition(max >= JRE.MINIMUM_RUNTIME_VERSION,
80-
() -> String.format("@%s's maximum value [%d] must be greater than or equal to %d", this.annotationName,
81-
max, JRE.MINIMUM_RUNTIME_VERSION));
8279

8380
return JRE.isCurrentVersionWithinRange(min, max);
8481
}
8582

86-
@SuppressWarnings("removal")
87-
private static JRE minJre() {
88-
return JRE.JAVA_8;
89-
}
90-
9183
}

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-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ public enum JRE {
8888

8989
static final int UNDEFINED_VERSION = -1;
9090

91-
static final int MINIMUM_DECLARED_VERSION = ${jres.getFirst().getVersion()};
92-
93-
static final int MINIMUM_RUNTIME_VERSION = ${minRuntimeVersion};
91+
static final int MINIMUM_VERSION = ${minRuntimeVersion};
9492

9593
private static final int CURRENT_VERSION = Runtime.version().feature();
9694

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

+1-11
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,10 @@ class DisabledOnJreConditionTests extends AbstractExecutionConditionTests {
7474
* @see DisabledOnJreIntegrationTests#version7()
7575
*/
7676
@Test
77-
void version7() {
78-
assertThatExceptionOfType(PreconditionViolationException.class)//
79-
.isThrownBy(this::evaluateCondition)//
80-
.withMessage("Version [7] in @DisabledOnJre must be greater than or equal to 8");
81-
}
82-
83-
/**
84-
* @see DisabledOnJreIntegrationTests#version16()
85-
*/
86-
@Test
8777
void version16() {
8878
assertThatExceptionOfType(PreconditionViolationException.class)//
8979
.isThrownBy(this::evaluateCondition)//
90-
.withMessage("Versions in @DisabledOnJre must contain at least one value greater than or equal to 17");
80+
.withMessage("Version [16] in @DisabledOnJre must be greater than or equal to 17");
9181
}
9282

9383
/**

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

-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ class DisabledOnJreIntegrationTests {
4848
void jreUndefined() {
4949
}
5050

51-
@Test
52-
@Disabled("Only used in a unit test via reflection")
53-
@DisabledOnJre(versions = 7)
54-
void version7() {
55-
}
56-
5751
@Test
5852
@Disabled("Only used in a unit test via reflection")
5953
@DisabledOnJre(versions = 16)

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

+1-11
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,14 @@ class EnabledOnJreConditionTests extends AbstractExecutionConditionTests {
7070
.withMessage("JRE.UNDEFINED is not supported in @EnabledOnJre");
7171
}
7272

73-
/**
74-
* @see EnabledOnJreIntegrationTests#version7()
75-
*/
76-
@Test
77-
void version7() {
78-
assertThatExceptionOfType(PreconditionViolationException.class)//
79-
.isThrownBy(this::evaluateCondition)//
80-
.withMessage("Version [7] in @EnabledOnJre must be greater than or equal to 8");
81-
}
82-
8373
/**
8474
* @see EnabledOnJreIntegrationTests#version16()
8575
*/
8676
@Test
8777
void version16() {
8878
assertThatExceptionOfType(PreconditionViolationException.class)//
8979
.isThrownBy(this::evaluateCondition)//
90-
.withMessage("Versions in @EnabledOnJre must contain at least one value greater than or equal to 17");
80+
.withMessage("Version [16] in @EnabledOnJre must be greater than or equal to 17");
9181
}
9282

9383
/**

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

-6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ class EnabledOnJreIntegrationTests {
4747
void jreUndefined() {
4848
}
4949

50-
@Test
51-
@Disabled("Only used in a unit test via reflection")
52-
@EnabledOnJre(versions = 7)
53-
void version7() {
54-
}
55-
5650
@Test
5751
@Disabled("Only used in a unit test via reflection")
5852
@EnabledOnJre(versions = 16)

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

+10-20
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,21 @@ 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

98-
/**
99-
* @see DisabledForJreRangeIntegrationTests#minVersion8Max11()
100-
*/
101-
@Test
102-
void minVersion8Max11() {
103-
assertThatExceptionOfType(PreconditionViolationException.class)//
104-
.isThrownBy(this::evaluateCondition)//
105-
.withMessage("@DisabledForJreRange's maximum value [11] must be greater than or equal to 17");
106-
}
107-
10898
/**
10999
* @see DisabledForJreRangeIntegrationTests#maxOther()
110100
*/
@@ -122,23 +112,23 @@ void maxVersionMaxInteger() {
122112
}
123113

124114
/**
125-
* @see DisabledForJreRangeIntegrationTests#minVersion7()
115+
* @see DisabledForJreRangeIntegrationTests#minVersion16()
126116
*/
127117
@Test
128-
void minVersion7() {
118+
void minVersion16() {
129119
assertThatExceptionOfType(PreconditionViolationException.class)//
130120
.isThrownBy(this::evaluateCondition)//
131-
.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");
132122
}
133123

134124
/**
135-
* @see DisabledForJreRangeIntegrationTests#maxVersion7()
125+
* @see DisabledForJreRangeIntegrationTests#maxVersion16()
136126
*/
137127
@Test
138-
void maxVersion7() {
128+
void maxVersion16() {
139129
assertThatExceptionOfType(PreconditionViolationException.class)//
140130
.isThrownBy(this::evaluateCondition)//
141-
.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");
142132
}
143133

144134
/**

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

+10-17
Original file line numberDiff line numberDiff line change
@@ -47,37 +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() {
74-
fail("should result in a configuration exception");
75-
}
76-
77-
@Test
78-
@Disabled("Only used in a unit test via reflection")
79-
@DisabledForJreRange(minVersion = 8, maxVersion = 11)
80-
void minVersion8Max11() {
72+
@DisabledForJreRange(minVersion = 17)
73+
void minVersion17() {
8174
fail("should result in a configuration exception");
8275
}
8376

@@ -97,15 +90,15 @@ void maxVersionMaxInteger() {
9790

9891
@Test
9992
@Disabled("Only used in a unit test via reflection")
100-
@DisabledForJreRange(minVersion = 7)
101-
void minVersion7() {
93+
@DisabledForJreRange(minVersion = 16)
94+
void minVersion16() {
10295
fail("should result in a configuration exception");
10396
}
10497

10598
@Test
10699
@Disabled("Only used in a unit test via reflection")
107-
@DisabledForJreRange(maxVersion = 7)
108-
void maxVersion7() {
100+
@DisabledForJreRange(maxVersion = 16)
101+
void maxVersion16() {
109102
fail("should result in a configuration exception");
110103
}
111104

0 commit comments

Comments
 (0)