Skip to content

Commit b4d1f56

Browse files
committed
Reliably support JRE.OTHER with @⁠EnabledOnJre and @⁠DisabledOnJre
In JUnit Jupiter 5.12, I added support for arbitrary Java versions with JRE conditions; however, I accidentally introduced a regression regarding support for JRE.OTHER. Specifically, prior to this commit, JRE.OTHER no longer worked reliably when used with @⁠EnabledOnJre or @⁠DisabledOnJre. To address that, this commit revises the logic in JRE.isCurrentVersion(int) to account for situations where the supplied version value is Integer.MAX_VALUE (representing @⁠EnabledOnJre(OTHER) or @⁠DisabledOnJre(OTHER)), and the current version of the JVM is greater than the version of the last JRE.JAVA_* enum constant — for example, when running on Java 27 and the last JRE enum constant is JAVA_26. See #3930 See #5341 Closes #5366
1 parent 5b6dfef commit b4d1f56

8 files changed

Lines changed: 106 additions & 13 deletions

File tree

documentation/modules/ROOT/pages/release-notes.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Please refer to the xref:overview.adoc[User Guide] for comprehensive
99
reference documentation for programmers writing tests, extension authors, and engine
1010
authors as well as build tool and IDE vendors.
1111

12+
include::partial$release-notes/release-notes-5.14.3.adoc[]
13+
1214
include::partial$release-notes/release-notes-5.14.2.adoc[]
1315

1416
include::partial$release-notes/release-notes-5.14.1.adoc[]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[[v5.14.3]]
2+
== 5.14.3
3+
4+
*Date of Release:* ❓
5+
6+
*Scope:* Bug fixes and enhancements since 5.14.2
7+
8+
For a complete list of all _closed_ issues and pull requests for this release, consult the
9+
link:{junit-framework-repo}+/milestone/116?closed=1+[5.14.3] milestone page in the JUnit
10+
repository on GitHub.
11+
12+
13+
[[v5.14.3-junit-platform]]
14+
=== JUnit Platform
15+
16+
[[v5.14.3-junit-platform-bug-fixes]]
17+
==== Bug Fixes
18+
19+
* ❓
20+
21+
[[v5.14.3-junit-platform-deprecations-and-breaking-changes]]
22+
==== Deprecations and Breaking Changes
23+
24+
* ❓
25+
26+
[[v5.14.3-junit-platform-new-features-and-improvements]]
27+
==== New Features and Improvements
28+
29+
* ❓
30+
31+
32+
[[v5.14.3-junit-jupiter]]
33+
=== JUnit Jupiter
34+
35+
[[v5.14.3-junit-jupiter-bug-fixes]]
36+
==== Bug Fixes
37+
38+
* `@EnabledOnJre` and `@DisabledOnJre` once again work reliably when used with `JRE.OTHER`
39+
in a test running on a Java runtime whose version is higher than the version of the last
40+
`JAVA_*` constant in the `JRE` enum.
41+
42+
[[v5.14.3-junit-jupiter-deprecations-and-breaking-changes]]
43+
==== Deprecations and Breaking Changes
44+
45+
* ❓
46+
47+
[[v5.14.3-junit-jupiter-new-features-and-improvements]]
48+
==== New Features and Improvements
49+
50+
* ❓
51+
52+
53+
[[v5.14.3-junit-vintage]]
54+
=== JUnit Vintage
55+
56+
[[v5.14.3-junit-vintage-bug-fixes]]
57+
==== Bug Fixes
58+
59+
* ❓
60+
61+
[[v5.14.3-junit-vintage-deprecations-and-breaking-changes]]
62+
==== Deprecations and Breaking Changes
63+
64+
* ❓
65+
66+
[[v5.14.3-junit-vintage-new-features-and-improvements]]
67+
==== New Features and Improvements
68+
69+
* ❓

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,30 @@ public enum JRE {
210210
}
211211

212212
/**
213-
* @return {@code true} if the supplied version number is known to be the
214-
* Java Runtime Environment version for the currently executing JVM or if
215-
* the supplied version number is {@code -1} and the current JVM version
216-
* could not be determined
213+
* Determine if the supplied version number is considered to be the current
214+
* JRE version.
215+
*
216+
* <p>Returns {@code true} if any of the following is {@code true}.
217217
*
218+
* <ul>
219+
* <li>The supplied version number is known to be the Java Runtime Environment
220+
* version for the currently executing JVM.</li>
221+
* <li>The supplied version number is {@link Integer#MAX_VALUE} and the current
222+
* {@code JRE} is {@link JRE#OTHER OTHER}.</li>
223+
* <li>The supplied version number is {@code -1} and the current {@code JRE}
224+
* is {@link JRE#UNDEFINED UNDEFINED}.</li>
225+
* </ul>
226+
*
227+
* @return {@code true} if the supplied version number is considered to be
228+
* the current JRE version
218229
* @since 5.12
219230
* @see Runtime.Version#feature()
231+
* @see #isCurrentVersion()
232+
* @see #currentJre()
220233
*/
221234
@API(status = MAINTAINED, since = "5.13.3")
222235
public static boolean isCurrentVersion(int version) {
223-
return version == CURRENT_VERSION;
236+
return (version == CURRENT_VERSION) || (version == JRE.currentJre().version);
224237
}
225238

226239
static boolean isCurrentVersionWithinRange(int min, int max) {

junit-jupiter-api/src/templates/resources/testFixtures/org/junit/jupiter/api/condition/JavaVersionPredicates.java.jte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ public class JavaVersionPredicates {
1919
return @for(var jre : ForSupport.of(jres))onJava${jre.get().getVersion()}()@if(!jre.isLast()) //
2020
|| @endif@endfor;
2121
}
22+
23+
static boolean onOtherVersion() {
24+
return JRE.OTHER.isCurrentVersion();
25+
}
26+
2227
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava8;
2424
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9;
2525
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
26+
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onOtherVersion;
2627
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationFor;
2728

2829
import org.junit.jupiter.api.Test;
@@ -266,7 +267,7 @@ void minVersion18MaxVersion19() {
266267
@Test
267268
void minOtherMaxOther() {
268269
evaluateCondition();
269-
assertDisabledOnCurrentJreIf(!onKnownVersion());
270+
assertDisabledOnCurrentJreIf(!(onKnownVersion() || onOtherVersion()));
270271
}
271272

272273
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava8;
3434
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9;
3535
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
36+
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onOtherVersion;
3637

3738
import org.junit.jupiter.api.Disabled;
3839
import org.junit.jupiter.api.Test;
@@ -206,7 +207,7 @@ void minVersion18MaxVersion19() {
206207
@Test
207208
@DisabledForJreRange(min = OTHER, max = OTHER)
208209
void minOtherMaxOther() {
209-
assertTrue(onKnownVersion());
210+
assertTrue(onKnownVersion() || onOtherVersion());
210211
}
211212

212213
@Test

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
@@ -30,6 +30,7 @@
3030
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava8;
3131
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9;
3232
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
33+
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onOtherVersion;
3334
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationFor;
3435

3536
import org.junit.jupiter.api.Test;
@@ -203,8 +204,8 @@ void minVersionGreaterThanMax() {
203204
@Test
204205
void min20() {
205206
evaluateCondition();
206-
assertEnabledOnCurrentJreIf(
207-
onJava20() || onJava21() || onJava22() || onJava23() || onJava24() || onJava25() || onJava26());
207+
assertEnabledOnCurrentJreIf(onJava20() || onJava21() || onJava22() || onJava23() || onJava24() || onJava25()
208+
|| onJava26() || onOtherVersion());
208209
}
209210

210211
/**
@@ -315,7 +316,7 @@ void minVersion20MaxVersion21() {
315316
void minVersion17MaxVersionMaxInteger() {
316317
evaluateCondition();
317318
assertEnabledOnCurrentJreIf(onJava17() || onJava18() || onJava19() || onJava20() || onJava21() || onJava22()
318-
|| onJava23() || onJava24() || onJava25() || onJava26());
319+
|| onJava23() || onJava24() || onJava25() || onJava26() || onOtherVersion());
319320
}
320321

321322
/**
@@ -324,7 +325,7 @@ void minVersion17MaxVersionMaxInteger() {
324325
@Test
325326
void minOtherMaxOther() {
326327
evaluateCondition();
327-
assertEnabledOnCurrentJreIf(!onKnownVersion());
328+
assertEnabledOnCurrentJreIf(!(onKnownVersion() || onOtherVersion()));
328329
}
329330

330331
/**

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava8;
3838
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9;
3939
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
40+
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onOtherVersion;
4041

4142
import org.junit.jupiter.api.Disabled;
4243
import org.junit.jupiter.api.Test;
@@ -163,7 +164,7 @@ void minVersionGreaterThanMax() {
163164
@Test
164165
@EnabledForJreRange(min = JAVA_20)
165166
void min20() {
166-
assertTrue(onKnownVersion());
167+
assertTrue(onKnownVersion() || onOtherVersion());
167168
assertTrue(JRE.currentVersionNumber() >= 20);
168169
assertTrue(CURRENT_JRE.compareTo(JAVA_20) >= 0);
169170
assertTrue(CURRENT_JRE.version() >= 20);
@@ -253,7 +254,7 @@ void minVersion20MaxVersion21() {
253254
@Test
254255
@EnabledForJreRange(minVersion = 17, maxVersion = Integer.MAX_VALUE)
255256
void minVersion17MaxVersionMaxInteger() {
256-
assertTrue(onKnownVersion());
257+
assertTrue(onKnownVersion() || onOtherVersion());
257258
assertTrue(JRE.currentVersionNumber() >= 17);
258259
}
259260

0 commit comments

Comments
 (0)