Skip to content

Commit a6eb2b1

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

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

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: 4 additions & 11 deletions
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

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

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 & 3 deletions
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

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

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

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

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

0 commit comments

Comments
 (0)