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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 3 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

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 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

Lines changed: 2 additions & 2 deletions
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

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#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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)