Skip to content

Commit 5c8fb0f

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 Closes #5341
1 parent febb13f commit 5c8fb0f

File tree

8 files changed

+105
-13
lines changed

8 files changed

+105
-13
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
This document contains the change log for all JUnit releases since 5.14 GA.
77

8+
include::partial$release-notes/release-notes-6.0.3.adoc[]
9+
810
include::partial$release-notes/release-notes-6.0.2.adoc[]
911

1012
include::partial$release-notes/release-notes-6.0.1.adoc[]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[[v6.0.3]]
2+
== 6.0.3
3+
4+
*Date of Release:* ❓
5+
6+
*Scope:* Bug fixes and enhancements since 6.0.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+[6.0.3] milestone page in the JUnit
10+
repository on GitHub.
11+
12+
13+
[[v6.0.3-junit-platform]]
14+
=== JUnit Platform
15+
16+
[[v6.0.3-junit-platform-bug-fixes]]
17+
==== Bug Fixes
18+
19+
* ❓
20+
21+
[[v6.0.3-junit-platform-deprecations-and-breaking-changes]]
22+
==== Deprecations and Breaking Changes
23+
24+
* ❓
25+
26+
[[v6.0.3-junit-platform-new-features-and-improvements]]
27+
==== New Features and Improvements
28+
29+
* ❓
30+
31+
32+
[[v6.0.3-junit-jupiter]]
33+
=== JUnit Jupiter
34+
35+
[[v6.0.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+
[[v6.0.3-junit-jupiter-deprecations-and-breaking-changes]]
43+
==== Deprecations and Breaking Changes
44+
45+
* ❓
46+
47+
[[v6.0.3-junit-jupiter-new-features-and-improvements]]
48+
==== New Features and Improvements
49+
50+
* ❓
51+
52+
53+
[[v6.0.3-junit-vintage]]
54+
=== JUnit Vintage
55+
56+
[[v6.0.3-junit-vintage-bug-fixes]]
57+
==== Bug Fixes
58+
59+
* ❓
60+
61+
[[v6.0.3-junit-vintage-deprecations-and-breaking-changes]]
62+
==== Deprecations and Breaking Changes
63+
64+
* ❓
65+
66+
[[v6.0.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: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,28 @@ public enum JRE {
169169
}
170170

171171
/**
172-
* {@return {@code true} if the supplied version number is known to be the
173-
* Java Runtime Environment version for the currently executing JVM or if
174-
* the supplied version number is {@code -1} and the current JVM version
175-
* could not be determined}
172+
* Determine if the supplied version number is considered to be the current
173+
* JRE version.
174+
*
175+
* <p>Returns {@code true} if either of the following is {@code true}.
176176
*
177+
* <ul>
178+
* <li>The supplied version number is known to be the Java Runtime Environment
179+
* version for the currently executing JVM.</li>
180+
* <li>The supplied version number is {@link Integer#MAX_VALUE} and the current
181+
* {@code JRE} is {@link JRE#OTHER OTHER}.</li>
182+
* </ul>
183+
*
184+
* @return {@code true} if the supplied version number is considered to be
185+
* the current JRE version
177186
* @since 5.12
178187
* @see Runtime.Version#feature()
188+
* @see #isCurrentVersion()
189+
* @see #currentJre()
179190
*/
180191
@API(status = MAINTAINED, since = "5.13.3")
181192
public static boolean isCurrentVersion(int version) {
182-
return version == CURRENT_VERSION;
193+
return (version == CURRENT_VERSION) || (version == JRE.currentJre().version);
183194
}
184195

185196
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(supportedJres))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
@@ -14,6 +14,7 @@
1414
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava18;
1515
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava19;
1616
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
17+
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onOtherVersion;
1718
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationFor;
1819

1920
import org.junit.jupiter.api.Test;
@@ -257,7 +258,7 @@ void minVersion18MaxVersion19() {
257258
@Test
258259
void minOtherMaxOther() {
259260
evaluateCondition();
260-
assertDisabledOnCurrentJreIf(!onKnownVersion());
261+
assertDisabledOnCurrentJreIf(!(onKnownVersion() || onOtherVersion()));
261262
}
262263

263264
/**

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
@@ -22,6 +22,7 @@
2222
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava18;
2323
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava19;
2424
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
25+
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onOtherVersion;
2526

2627
import org.junit.jupiter.api.Disabled;
2728
import org.junit.jupiter.api.Test;
@@ -194,7 +195,7 @@ void minVersion18MaxVersion19() {
194195
@Test
195196
@DisabledForJreRange(min = OTHER, max = OTHER)
196197
void minOtherMaxOther() {
197-
assertTrue(onKnownVersion());
198+
assertTrue(onKnownVersion() || onOtherVersion());
198199
}
199200

200201
@Test

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava25;
2222
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava26;
2323
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
24+
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onOtherVersion;
2425
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationFor;
2526

2627
import org.junit.jupiter.api.Test;
@@ -195,8 +196,8 @@ void minVersionGreaterThanMax() {
195196
@Test
196197
void min20() {
197198
evaluateCondition();
198-
assertEnabledOnCurrentJreIf(
199-
onJava20() || onJava21() || onJava22() || onJava23() || onJava24() || onJava25() || onJava26());
199+
assertEnabledOnCurrentJreIf(onJava20() || onJava21() || onJava22() || onJava23() || onJava24() || onJava25()
200+
|| onJava26() || onOtherVersion());
200201
}
201202

202203
/**
@@ -304,7 +305,8 @@ void minVersion20MaxVersion21() {
304305
@Test
305306
void minVersion21MaxVersionMaxInteger() {
306307
evaluateCondition();
307-
assertEnabledOnCurrentJreIf(onJava21() || onJava22() || onJava23() || onJava24() || onJava25() || onJava26());
308+
assertEnabledOnCurrentJreIf(
309+
onJava21() || onJava22() || onJava23() || onJava24() || onJava25() || onJava26() || onOtherVersion());
308310
}
309311

310312
/**
@@ -313,7 +315,7 @@ void minVersion21MaxVersionMaxInteger() {
313315
@Test
314316
void minOtherMaxOther() {
315317
evaluateCondition();
316-
assertEnabledOnCurrentJreIf(!onKnownVersion());
318+
assertEnabledOnCurrentJreIf(!(onKnownVersion() || onOtherVersion()));
317319
}
318320

319321
/**

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
@@ -26,6 +26,7 @@
2626
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava22;
2727
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava23;
2828
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
29+
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onOtherVersion;
2930

3031
import org.junit.jupiter.api.Disabled;
3132
import org.junit.jupiter.api.Test;
@@ -152,7 +153,7 @@ void minVersionGreaterThanMax() {
152153
@Test
153154
@EnabledForJreRange(min = JAVA_20)
154155
void min20() {
155-
assertTrue(onKnownVersion());
156+
assertTrue(onKnownVersion() || onOtherVersion());
156157
assertTrue(JRE.currentVersionNumber() >= 20);
157158
assertTrue(CURRENT_JRE.compareTo(JAVA_20) >= 0);
158159
assertTrue(CURRENT_JRE.version() >= 20);
@@ -241,7 +242,7 @@ void minVersion20MaxVersion21() {
241242
@Test
242243
@EnabledForJreRange(minVersion = 21, maxVersion = Integer.MAX_VALUE)
243244
void minVersion21MaxVersionMaxInteger() {
244-
assertTrue(onKnownVersion());
245+
assertTrue(onKnownVersion() || onOtherVersion());
245246
assertTrue(JRE.currentVersionNumber() >= 21);
246247
}
247248

0 commit comments

Comments
 (0)