Version ranges can be specified as {@link JRE} enum constants via {@link #min} + * and {@link #max} or as integers via {@link #minVersion} and {@link #maxVersion}. * *
When applied at the class level, all test methods within that class will * be disabled on the same specified JRE versions. @@ -82,28 +86,74 @@ public @interface DisabledForJreRange { /** - * Java Runtime Environment version which is used as the lower boundary - * for the version range that determines if the annotated class or method - * should be disabled. + * Java Runtime Environment version which is used as the lower boundary for + * the version range that determines if the annotated class or method should + * be disabled, specified as a {@link JRE} enum constant. + * + *
If a {@code JRE} enum constant does not exist for a particular JRE + * version, you can specify the minimum version via {@link #minVersion()} + * instead. * - *
Defaults to {@link JRE#JAVA_8 JAVA_8}, as this is the lowest - * supported JRE version. + *
Defaults to {@link JRE#UNDEFINED UNDEFINED}, which will be interpreted + * as {@link JRE#JAVA_8 JAVA_8} if the {@link #minVersion()} is not set. * * @see JRE + * @see #minVersion() */ - JRE min() default JRE.JAVA_8; + JRE min() default JRE.UNDEFINED; /** - * Java Runtime Environment version which is used as the upper boundary - * for the version range that determines if the annotated class or method - * should be disabled. + * Java Runtime Environment version which is used as the upper boundary for + * the version range that determines if the annotated class or method should + * be disabled, specified as a {@link JRE} enum constant. * - *
Defaults to {@link JRE#OTHER OTHER}, as this will always be the highest - * possible version. + *
If a {@code JRE} enum constant does not exist for a particular JRE + * version, you can specify the maximum version via {@link #maxVersion()} + * instead. + * + *
Defaults to {@link JRE#UNDEFINED UNDEFINED}, which will be interpreted + * as {@link JRE#OTHER OTHER} if the {@link #maxVersion()} is not set. * * @see JRE + * @see #maxVersion() + */ + JRE max() default JRE.UNDEFINED; + + /** + * Java Runtime Environment version which is used as the lower boundary for + * the version range that determines if the annotated class or method should + * be disabled, specified as an integer. + * + *
If a {@code JRE} enum constant exists for the particular JRE version, + * you can specify the minimum version via {@link #min()} instead. + * + *
Defaults to {@code -1} to signal that {@link #min()} should be used instead. + * + * @since 5.12 + * @see #min() + * @see JRE#featureVersion() + * @see Runtime.Version#feature() + */ + @API(status = EXPERIMENTAL, since = "5.12") + int minVersion() default -1; + + /** + * Java Runtime Environment version which is used as the upper boundary for + * the version range that determines if the annotated class or method should + * be disabled, specified as an integer. + * + *
If a {@code JRE} enum constant exists for the particular JRE version, + * you can specify the maximum version via {@link #max()} instead. + * + *
Defaults to {@code -1} to signal that {@link #max()} should be used instead.
+ *
+ * @since 5.12
+ * @see #max()
+ * @see JRE#featureVersion()
+ * @see Runtime.Version#feature()
*/
- JRE max() default JRE.OTHER;
+ @API(status = EXPERIMENTAL, since = "5.12")
+ int maxVersion() default -1;
/**
* Custom reason to provide if the test or container is disabled.
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRangeCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRangeCondition.java
index b62e7053c4de..f9fc9c1be1a1 100644
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRangeCondition.java
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRangeCondition.java
@@ -10,11 +10,10 @@
package org.junit.jupiter.api.condition;
-import static org.junit.jupiter.api.condition.EnabledOnJreCondition.DISABLED_ON_CURRENT_JRE;
-import static org.junit.jupiter.api.condition.EnabledOnJreCondition.ENABLED_ON_CURRENT_JRE;
+import static org.junit.jupiter.api.condition.AbstractJreCondition.DISABLED_ON_CURRENT_JRE;
+import static org.junit.jupiter.api.condition.AbstractJreCondition.ENABLED_ON_CURRENT_JRE;
import org.junit.jupiter.api.extension.ExecutionCondition;
-import org.junit.platform.commons.util.Preconditions;
/**
* {@link ExecutionCondition} for {@link DisabledForJreRange @DisabledForJreRange}.
@@ -31,15 +30,8 @@ class DisabledForJreRangeCondition extends BooleanExecutionCondition Versions can be specified as {@link JRE} enum constants via {@link #value()}
+ * or as integers via {@link #versions()}.
*
* When applied at the class level, all test methods within that class
* will be disabled on the same specified JRE versions.
@@ -82,12 +86,31 @@
public @interface DisabledOnJre {
/**
- * Java Runtime Environment versions on which the annotated class or
- * method should be disabled.
+ * Java Runtime Environment versions on which the annotated class or method
+ * should be disabled, specified as {@link JRE} enum constants.
+ *
+ * If a {@code JRE} enum constant does not exist for a particular JRE
+ * version, you can specify the version via {@link #versions()} instead.
*
* @see JRE
+ * @see #versions()
+ */
+ JRE[] value() default {};
+
+ /**
+ * Java Runtime Environment versions on which the annotated class or method
+ * should be disabled, specified as integers.
+ *
+ * If a {@code JRE} enum constant exists for a particular JRE version, you
+ * can specify the version via {@link #value()} instead.
+ *
+ * @since 5.12
+ * @see #value()
+ * @see JRE#featureVersion()
+ * @see Runtime.Version#feature()
*/
- JRE[] value();
+ @API(status = EXPERIMENTAL, since = "5.12")
+ int[] versions() default {};
/**
* Custom reason to provide if the test or container is disabled.
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJreCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJreCondition.java
index aa74770bc3cd..087cf1e3d76d 100644
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJreCondition.java
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJreCondition.java
@@ -10,13 +10,9 @@
package org.junit.jupiter.api.condition;
-import static org.junit.jupiter.api.condition.EnabledOnJreCondition.DISABLED_ON_CURRENT_JRE;
-import static org.junit.jupiter.api.condition.EnabledOnJreCondition.ENABLED_ON_CURRENT_JRE;
-
import java.util.Arrays;
import org.junit.jupiter.api.extension.ExecutionCondition;
-import org.junit.platform.commons.util.Preconditions;
/**
* {@link ExecutionCondition} for {@link DisabledOnJre @DisabledOnJre}.
@@ -24,17 +20,19 @@
* @since 5.1
* @see DisabledOnJre
*/
-class DisabledOnJreCondition extends BooleanExecutionCondition Version ranges can be specified as {@link JRE} enum constants via {@link #min}
+ * and {@link #max} or as integers via {@link #minVersion} and {@link #maxVersion}.
*
* When applied at the class level, all test methods within that class will
* be enabled on the same specified JRE versions.
@@ -82,28 +86,74 @@
public @interface EnabledForJreRange {
/**
- * Java Runtime Environment version which should be used as the lower boundary
- * for the version range that determines if the annotated class or method
- * should be enabled.
+ * Java Runtime Environment version which is used as the lower boundary for
+ * the version range that determines if the annotated class or method should
+ * be enabled, specified as a {@link JRE} enum constant.
+ *
+ * If a {@code JRE} enum constant does not exist for a particular JRE
+ * version, you can specify the minimum version via {@link #minVersion()}
+ * instead.
*
- * Defaults to {@link JRE#JAVA_8 JAVA_8}, as this is the lowest
- * supported JRE version.
+ * Defaults to {@link JRE#UNDEFINED UNDEFINED}, which will be interpreted
+ * as {@link JRE#JAVA_8 JAVA_8} if the {@link #minVersion()} is not set.
*
* @see JRE
+ * @see #minVersion()
*/
- JRE min() default JRE.JAVA_8;
+ JRE min() default JRE.UNDEFINED;
/**
- * Java Runtime Environment version which should be used as the upper boundary
- * for the version range that determines if the annotated class or method
- * should be enabled.
+ * Java Runtime Environment version which is used as the upper boundary for
+ * the version range that determines if the annotated class or method should
+ * be enabled, specified as a {@link JRE} enum constant.
*
- * Defaults to {@link JRE#OTHER OTHER}, as this will always be the highest
- * possible version.
+ * If a {@code JRE} enum constant does not exist for a particular JRE
+ * version, you can specify the maximum version via {@link #maxVersion()}
+ * instead.
+ *
+ * Defaults to {@link JRE#UNDEFINED UNDEFINED}, which will be interpreted
+ * as {@link JRE#OTHER OTHER} if the {@link #maxVersion()} is not set.
*
* @see JRE
+ * @see #maxVersion()
+ */
+ JRE max() default JRE.UNDEFINED;
+
+ /**
+ * Java Runtime Environment version which is used as the lower boundary for
+ * the version range that determines if the annotated class or method should
+ * be enabled, specified as an integer.
+ *
+ * If a {@code JRE} enum constant exists for the particular JRE version,
+ * you can specify the minimum version via {@link #min()} instead.
+ *
+ * Defaults to {@code -1} to signal that {@link #min()} should be used instead.
+ *
+ * @since 5.12
+ * @see #min()
+ * @see JRE#featureVersion()
+ * @see Runtime.Version#feature()
+ */
+ @API(status = EXPERIMENTAL, since = "5.12")
+ int minVersion() default -1;
+
+ /**
+ * Java Runtime Environment version which is used as the upper boundary for
+ * the version range that determines if the annotated class or method should
+ * be enabled, specified as an integer.
+ *
+ * If a {@code JRE} enum constant exists for the particular JRE version,
+ * you can specify the maximum version via {@link #max()} instead.
+ *
+ * Defaults to {@code -1} to signal that {@link #max()} should be used instead.
+ *
+ * @since 5.12
+ * @see #max()
+ * @see JRE#featureVersion()
+ * @see Runtime.Version#feature()
*/
- JRE max() default JRE.OTHER;
+ @API(status = EXPERIMENTAL, since = "5.12")
+ int maxVersion() default -1;
/**
* Custom reason to provide if the test or container is disabled.
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.java
index abb5001a7ccf..754523fb9b5e 100644
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.java
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.java
@@ -10,8 +10,8 @@
package org.junit.jupiter.api.condition;
-import static org.junit.jupiter.api.condition.EnabledOnJreCondition.DISABLED_ON_CURRENT_JRE;
-import static org.junit.jupiter.api.condition.EnabledOnJreCondition.ENABLED_ON_CURRENT_JRE;
+import static org.junit.jupiter.api.condition.AbstractJreCondition.DISABLED_ON_CURRENT_JRE;
+import static org.junit.jupiter.api.condition.AbstractJreCondition.ENABLED_ON_CURRENT_JRE;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.platform.commons.util.Preconditions;
@@ -31,13 +31,54 @@ class EnabledForJreRangeCondition extends BooleanExecutionCondition Versions can be specified as {@link JRE} enum constants via {@link #value()}
+ * or as integers via {@link #versions()}.
*
* When applied at the class level, all test methods within that class
* will be enabled on the same specified JRE versions.
@@ -82,12 +86,31 @@
public @interface EnabledOnJre {
/**
- * Java Runtime Environment versions on which the annotated class or
- * method should be enabled.
+ * Java Runtime Environment versions on which the annotated class or method
+ * should be enabled, specified as {@link JRE} enum constants.
+ *
+ * If a {@code JRE} enum constant does not exist for a particular JRE
+ * version, you can specify the version via {@link #versions()} instead.
*
* @see JRE
+ * @see #versions()
+ */
+ JRE[] value() default {};
+
+ /**
+ * Java Runtime Environment versions on which the annotated class or method
+ * should be enabled, specified as integers.
+ *
+ * If a {@code JRE} enum constant exists for a particular JRE version, you
+ * can specify the version via {@link #value()} instead.
+ *
+ * @since 5.12
+ * @see #value()
+ * @see JRE#featureVersion()
+ * @see Runtime.Version#feature()
*/
- JRE[] value();
+ @API(status = EXPERIMENTAL, since = "5.12")
+ int[] versions() default {};
/**
* Custom reason to provide if the test or container is disabled.
@@ -100,4 +123,5 @@
*/
@API(status = STABLE, since = "5.7")
String disabledReason() default "";
+
}
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledOnJreCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledOnJreCondition.java
index 674d0687856c..e9c637bd19f4 100644
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledOnJreCondition.java
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledOnJreCondition.java
@@ -13,7 +13,6 @@
import java.util.Arrays;
import org.junit.jupiter.api.extension.ExecutionCondition;
-import org.junit.platform.commons.util.Preconditions;
/**
* {@link ExecutionCondition} for {@link EnabledOnJre @EnabledOnJre}.
@@ -21,23 +20,19 @@
* @since 5.1
* @see EnabledOnJre
*/
-class EnabledOnJreCondition extends BooleanExecutionCondition This constant is used by JUnit as a default configuration value but is
+ * not intended to be used by users.
+ *
+ * This constant returns {@code -1} for its {@link #version() version}.
+ *
+ * @since 5.12
+ */
+ @API(status = EXPERIMENTAL, since = "5.12")
+ UNDEFINED(-1),
@for(var jre : jres)
/**
* Java ${jre.getVersion()}.
@@ -49,7 +63,7 @@ public enum JRE {
@if(jre.getSince() != null)<%--
--%>@API(status = STABLE, since = "${jre.getSince()}")
@endif<%--
---%>JAVA_${jre.getVersion()},
+--%>JAVA_${jre.getVersion()}(${jre.getVersion()}),
@endfor
/**
* A JRE version other than <%--
@@ -60,14 +74,21 @@ public enum JRE {
--%>@if(jre.getIndex() % 3 == 1 && !jre.isLast())
* @elseif(!jre.isLast()) @endif<%--
--%>@endfor
+ *
+ * This constant returns {@link Integer#MAX_VALUE} for its
+ * {@link #version() version}.
*/
- OTHER;
+ OTHER(Integer.MAX_VALUE);
+
+ static final int UNDEFINED_VERSION = -1;
private static final Logger logger = LoggerFactory.getLogger(JRE.class);
- private static final JRE CURRENT_VERSION = determineCurrentVersion();
+ private static final int CURRENT_VERSION = determineCurrentVersion();
- private static JRE determineCurrentVersion() {
+ private static final JRE CURRENT_JRE = determineCurrentJre(CURRENT_VERSION);
+
+ private static int determineCurrentVersion() {
String javaVersion = System.getProperty("java.version");
boolean javaVersionIsBlank = StringUtils.isBlank(javaVersion);
@@ -77,7 +98,7 @@ public enum JRE {
}
if (!javaVersionIsBlank && javaVersion.startsWith("1.8")) {
- return JAVA_8;
+ return 8;
}
try {
@@ -87,48 +108,121 @@ public enum JRE {
Method versionMethod = Runtime.class.getMethod("version");
Object version = ReflectionSupport.invokeMethod(versionMethod, null);
Method majorMethod = version.getClass().getMethod("major");
- int major = (int) ReflectionSupport.invokeMethod(majorMethod, version);
- switch (major) {<%--
- --%>@for(var jre : jres)<%--
- --%>@if(jre.getVersion() != 8)
- case ${jre.getVersion()}:
- return JAVA_${jre.getVersion()};<%--
- --%>@endif<%--
- --%>@endfor
- default:
- return OTHER;
- }
+ return (int) ReflectionSupport.invokeMethod(majorMethod, version);
}
catch (Exception ex) {
logger.debug(ex, () -> "Failed to determine the current JRE version via java.lang.Runtime.Version.");
}
- // null signals that the current JRE version is "unknown"
- return null;
+ return UNDEFINED_VERSION;
+ }
+
+ private static JRE determineCurrentJre(int currentVersion) {
+ switch (currentVersion) {
+ case UNDEFINED_VERSION:
+ // null signals that the current JRE version is undefined.
+ return null;<%--
+ --%>@for(var jre : jres)
+ case ${jre.getVersion()}:
+ return JAVA_${jre.getVersion()};<%--
+ --%>@endfor
+ default:
+ return OTHER;
+ }
+ }
+
+ private final int version;
+
+ private JRE(int version) {
+ this.version = version;
+ }
+
+ /**
+ * Get the version of this {@code JRE}.
+ *
+ * If this {@code JRE} is {@link #UNDEFINED}, this method returns
+ * {@code -1}. If this {@code JRE} is {@link #OTHER}, this method returns
+ * {@link Integer#MAX_VALUE}.
+ *
+ * @return the version of this {@code JRE}
+ * @since 5.12
+ * @see Runtime.Version#feature()
+ * @see #currentVersionNumber()
+ */
+ @API(status = EXPERIMENTAL, since = "5.12")
+ public int version() {
+ return this.version;
}
/**
* @return {@code true} if this {@code JRE} is known to be the
* Java Runtime Environment version for the currently executing JVM or if
* the version is {@link #OTHER}
+ *
+ * @see #currentJre()
+ * @see #currentVersionNumber()
*/
public boolean isCurrentVersion() {
- return this == CURRENT_VERSION;
+ return this == CURRENT_JRE;
}
/**
* @return the {@link JRE} for the currently executing JVM, potentially
- * {@link #OTHER}
+ * {@link #OTHER} or {@code null} if the current JVM version could not be
+ * determined
*
* @since 5.7
+ * @see #currentVersionNumber()
+ * @deprecated in favor of {@link #currentJre()}
*/
- @API(status = STABLE, since = "5.7")
+ @API(status = DEPRECATED, since = "5.12")
+ @Deprecated
public static JRE currentVersion() {
+ return currentJre();
+ }
+
+ /**
+ * @return the {@link JRE} for the currently executing JVM, potentially
+ * {@link #OTHER} or {@code null} if the current JVM version could not be
+ * determined
+ *
+ * @since 5.12
+ * @see #currentVersionNumber()
+ */
+ @API(status = EXPERIMENTAL, since = "5.12")
+ public static JRE currentJre() {
+ return CURRENT_JRE;
+ }
+
+ /**
+ * @return the version number for the currently executing JVM, or {@code -1}
+ * if the current JVM version could not be determined
+ *
+ * @since 5.12
+ * @see Runtime.Version#feature()
+ * @see #currentJre()
+ */
+ @API(status = EXPERIMENTAL, since = "5.12")
+ public static int currentVersionNumber() {
return CURRENT_VERSION;
}
- static boolean isCurrentVersionWithinRange(JRE min, JRE max) {
- return EnumSet.range(min, max).contains(CURRENT_VERSION);
+ /**
+ * @return {@code true} if the supplied version number is known to be the
+ * Java Runtime Environment version for the currently executing JVM or if
+ * the supplied version number is {@code -1} and the current JVM version
+ * could not be determined
+ *
+ * @since 5.12
+ * @see Runtime.Version#feature()
+ */
+ @API(status = EXPERIMENTAL, since = "5.12")
+ public static boolean isCurrentVersion(int version) {
+ return version == CURRENT_VERSION;
+ }
+
+ static boolean isCurrentVersionWithinRange(int min, int max) {
+ return CURRENT_VERSION >= min && CURRENT_VERSION <= max;
}
}
diff --git a/junit-jupiter-api/src/templates/resources/testFixtures/org/junit/jupiter/api/condition/JavaVersionPredicates.java.jte b/junit-jupiter-api/src/templates/resources/testFixtures/org/junit/jupiter/api/condition/JavaVersionPredicates.java.jte
index de731bb4cd8f..41db82bc794e 100644
--- a/junit-jupiter-api/src/templates/resources/testFixtures/org/junit/jupiter/api/condition/JavaVersionPredicates.java.jte
+++ b/junit-jupiter-api/src/templates/resources/testFixtures/org/junit/jupiter/api/condition/JavaVersionPredicates.java.jte
@@ -9,10 +9,10 @@ package org.junit.jupiter.api.condition;
public class JavaVersionPredicates {
- private static final String JAVA_VERSION = System.getProperty("java.version");
+ private static final int JAVA_VERSION = Runtime.version().feature();
@for(JRE jre : jres)
static boolean onJava${jre.getVersion()}() {
- return JAVA_VERSION.startsWith("@if(jre.getVersion() == 8)1.@endif${jre.getVersion()}");
+ return JAVA_VERSION == ${jre.getVersion()};
}
@endfor
static boolean onKnownVersion() {
diff --git a/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreConditionTests.java.jte b/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreConditionTests.java.jte
index fc4d8884be75..b6ce05e15fa6 100644
--- a/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreConditionTests.java.jte
+++ b/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreConditionTests.java.jte
@@ -7,8 +7,7 @@
${licenseHeader}
package org.junit.jupiter.api.condition;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@for(var jre : jresSortedByStringValue)<%--
--%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()};
@endfor<%--
@@ -19,7 +18,8 @@ import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.platform.commons.PreconditionViolationException;
/**
- * Unit tests for {@link DisabledOnJreCondition}.
+ * Unit tests for {@link DisabledOnJreCondition}, generated from
+ * {@code DisabledOnJreConditionTests.java.jte}.
*
* Note that test method names MUST match the test method names in
* {@link DisabledOnJreIntegrationTests}.
@@ -28,6 +28,8 @@ import org.junit.platform.commons.PreconditionViolationException;
*/
class DisabledOnJreConditionTests extends AbstractExecutionConditionTests {
+ private static final String JAVA_VERSION = System.getProperty("java.version");
+
@Override
protected ExecutionCondition getExecutionCondition() {
return new DisabledOnJreCondition();
@@ -49,12 +51,33 @@ class DisabledOnJreConditionTests extends AbstractExecutionConditionTests {
}
/**
- * @see DisabledOnJreIntegrationTests#missingJreDeclaration()
+ * @see DisabledOnJreIntegrationTests#missingVersionDeclaration()
+ */
+ @Test
+ void missingVersionDeclaration() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage("You must declare at least one JRE or version in @DisabledOnJre");
+ }
+
+ /**
+ * @see DisabledOnJreIntegrationTests#jreUndefined()
+ */
+ @Test
+ void jreUndefined() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage("JRE.UNDEFINED is not supported in @DisabledOnJre");
+ }
+
+ /**
+ * @see DisabledOnJreIntegrationTests#version7()
*/
@Test
- void missingJreDeclaration() {
- Exception exception = assertThrows(PreconditionViolationException.class, this::evaluateCondition);
- assertThat(exception).hasMessageContaining("You must declare at least one JRE");
+ void version7() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage("Version [7] in @DisabledOnJre must be greater than or equal to 8");
}
/**
@@ -68,10 +91,20 @@ class DisabledOnJreConditionTests extends AbstractExecutionConditionTests {
}
@for(var jre : jres)
/**
- * @see DisabledOnJreIntegrationTests#java${jre.getVersion()}()
+ * @see DisabledOnJreIntegrationTests#jre${jre.getVersion()}()
+ */
+ @Test
+ void jre${jre.getVersion()}() {
+ evaluateCondition();
+ assertDisabledOnCurrentJreIf(onJava${jre.getVersion()}());
+ }
+@endfor<%--
+--%>@for(var jre : jres)
+ /**
+ * @see DisabledOnJreIntegrationTests#version${jre.getVersion()}()
*/
@Test
- void java${jre.getVersion()}() {
+ void version${jre.getVersion()}() {
evaluateCondition();
assertDisabledOnCurrentJreIf(onJava${jre.getVersion()}());
}
@@ -88,11 +121,11 @@ class DisabledOnJreConditionTests extends AbstractExecutionConditionTests {
private void assertDisabledOnCurrentJreIf(boolean condition) {
if (condition) {
assertDisabled();
- assertReasonContains("Disabled on JRE version: " + System.getProperty("java.version"));
+ assertReasonContains("Disabled on JRE version: " + JAVA_VERSION);
}
else {
assertEnabled();
- assertReasonContains("Enabled on JRE version: " + System.getProperty("java.version"));
+ assertReasonContains("Enabled on JRE version: " + JAVA_VERSION);
}
}
diff --git a/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreIntegrationTests.java.jte b/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreIntegrationTests.java.jte
index 6d86cd5c670b..c84b159c4078 100644
--- a/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreIntegrationTests.java.jte
+++ b/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/DisabledOnJreIntegrationTests.java.jte
@@ -14,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.fail;
--%>import static org.junit.jupiter.api.condition.JRE.JAVA_${jre.getVersion()};
@endfor<%--
--%>import static org.junit.jupiter.api.condition.JRE.OTHER;
+import static org.junit.jupiter.api.condition.JRE.UNDEFINED;
@for(var jre : jresSortedByStringValue)<%--
--%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()};
@endfor<%--
@@ -23,7 +24,8 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
- * Integration tests for {@link DisabledOnJre}.
+ * Integration tests for {@link DisabledOnJre @DisabledOnJre}, generated from
+ * {@code DisabledOnJreIntegrationTests.java.jte}.
*
* @since 5.1
*/
@@ -37,7 +39,19 @@ class DisabledOnJreIntegrationTests {
@Test
@Disabled("Only used in a unit test via reflection")
@DisabledOnJre({})
- void missingJreDeclaration() {
+ void missingVersionDeclaration() {
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @DisabledOnJre(UNDEFINED)
+ void jreUndefined() {
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @DisabledOnJre(versions = 7)
+ void version7() {
}
@Test
@@ -53,7 +67,14 @@ class DisabledOnJreIntegrationTests {
@for(var jre : jres)
@Test
@DisabledOnJre(JAVA_${jre.getVersion()})
- void java${jre.getVersion()}() {
+ void jre${jre.getVersion()}() {
+ assertFalse(onJava${jre.getVersion()}());
+ }
+@endfor<%--
+--%>@for(var jre : jres)
+ @Test
+ @DisabledOnJre(versions = ${jre.getVersion()})
+ void version${jre.getVersion()}() {
assertFalse(onJava${jre.getVersion()}());
}
@endfor
diff --git a/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreConditionTests.java.jte b/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreConditionTests.java.jte
index 81c9e1cc4dfd..9d6a1ee02021 100644
--- a/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreConditionTests.java.jte
+++ b/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreConditionTests.java.jte
@@ -7,8 +7,7 @@
${licenseHeader}
package org.junit.jupiter.api.condition;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@for(var jre : jresSortedByStringValue)<%--
--%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()};
@endfor<%--
@@ -19,7 +18,8 @@ import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.platform.commons.PreconditionViolationException;
/**
- * Unit tests for {@link EnabledOnJreCondition}.
+ * Unit tests for {@link EnabledOnJreCondition}, generated from
+ * {@code EnabledOnJreConditionTests.java.jte}.
*
* Note that test method names MUST match the test method names in
* {@link EnabledOnJreIntegrationTests}.
@@ -28,6 +28,8 @@ import org.junit.platform.commons.PreconditionViolationException;
*/
class EnabledOnJreConditionTests extends AbstractExecutionConditionTests {
+ private static final String JAVA_VERSION = System.getProperty("java.version");
+
@Override
protected ExecutionCondition getExecutionCondition() {
return new EnabledOnJreCondition();
@@ -49,12 +51,33 @@ class EnabledOnJreConditionTests extends AbstractExecutionConditionTests {
}
/**
- * @see EnabledOnJreIntegrationTests#missingJreDeclaration()
+ * @see EnabledOnJreIntegrationTests#missingVersionDeclaration()
+ */
+ @Test
+ void missingVersionDeclaration() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage("You must declare at least one JRE or version in @EnabledOnJre");
+ }
+
+ /**
+ * @see EnabledOnJreIntegrationTests#jreUndefined()
+ */
+ @Test
+ void jreUndefined() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage("JRE.UNDEFINED is not supported in @EnabledOnJre");
+ }
+
+ /**
+ * @see EnabledOnJreIntegrationTests#version7()
*/
@Test
- void missingJreDeclaration() {
- Exception exception = assertThrows(PreconditionViolationException.class, this::evaluateCondition);
- assertThat(exception).hasMessageContaining("You must declare at least one JRE");
+ void version7() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage("Version [7] in @EnabledOnJre must be greater than or equal to 8");
}
/**
@@ -67,10 +90,20 @@ class EnabledOnJreConditionTests extends AbstractExecutionConditionTests {
}
@for(var jre : jres)
/**
- * @see EnabledOnJreIntegrationTests#java${jre.getVersion()}()
+ * @see EnabledOnJreIntegrationTests#jre${jre.getVersion()}()
+ */
+ @Test
+ void jre${jre.getVersion()}() {
+ evaluateCondition();
+ assertEnabledOnCurrentJreIf(onJava${jre.getVersion()}());
+ }
+@endfor<%--
+--%>@for(var jre : jres)
+ /**
+ * @see EnabledOnJreIntegrationTests#version${jre.getVersion()}()
*/
@Test
- void java${jre.getVersion()}() {
+ void version${jre.getVersion()}() {
evaluateCondition();
assertEnabledOnCurrentJreIf(onJava${jre.getVersion()}());
}
@@ -88,11 +121,11 @@ class EnabledOnJreConditionTests extends AbstractExecutionConditionTests {
private void assertEnabledOnCurrentJreIf(boolean condition) {
if (condition) {
assertEnabled();
- assertReasonContains("Enabled on JRE version: " + System.getProperty("java.version"));
+ assertReasonContains("Enabled on JRE version: " + JAVA_VERSION);
}
else {
assertDisabled();
- assertReasonContains("Disabled on JRE version: " + System.getProperty("java.version"));
+ assertReasonContains("Disabled on JRE version: " + JAVA_VERSION);
}
}
diff --git a/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreIntegrationTests.java.jte b/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreIntegrationTests.java.jte
index 7aee1f374c73..c3b71df58ab4 100644
--- a/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreIntegrationTests.java.jte
+++ b/jupiter-tests/src/templates/resources/test/org/junit/jupiter/api/condition/EnabledOnJreIntegrationTests.java.jte
@@ -13,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
--%>import static org.junit.jupiter.api.condition.JRE.JAVA_${jre.getVersion()};
@endfor<%--
--%>import static org.junit.jupiter.api.condition.JRE.OTHER;
+import static org.junit.jupiter.api.condition.JRE.UNDEFINED;
@for(var jre : jresSortedByStringValue)<%--
--%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()};
@endfor<%--
@@ -22,7 +23,8 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
- * Integration tests for {@link EnabledOnJre}.
+ * Integration tests for {@link EnabledOnJre @EnabledOnJre}, generated from
+ * {@code EnabledOnJreIntegrationTests.java.jte}.
*
* @since 5.1
*/
@@ -36,7 +38,19 @@ class EnabledOnJreIntegrationTests {
@Test
@Disabled("Only used in a unit test via reflection")
@EnabledOnJre({})
- void missingJreDeclaration() {
+ void missingVersionDeclaration() {
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledOnJre(UNDEFINED)
+ void jreUndefined() {
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledOnJre(versions = 7)
+ void version7() {
}
@Test
@@ -51,7 +65,14 @@ class EnabledOnJreIntegrationTests {
@for(var jre : jres)
@Test
@EnabledOnJre(JAVA_${jre.getVersion()})
- void java${jre.getVersion()}() {
+ void jre${jre.getVersion()}() {
+ assertTrue(onJava${jre.getVersion()}());
+ }
+@endfor<%--
+--%>@for(var jre : jres)
+ @Test
+ @EnabledOnJre(versions = ${jre.getVersion()})
+ void version${jre.getVersion()}() {
assertTrue(onJava${jre.getVersion()}());
}
@endfor
diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/AbstractExecutionConditionTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/AbstractExecutionConditionTests.java
index 2dceb1d3f2a8..bff8050468de 100644
--- a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/AbstractExecutionConditionTests.java
+++ b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/AbstractExecutionConditionTests.java
@@ -65,7 +65,7 @@ void ensureAllTestMethodsAreCovered() {
List Note that test method names MUST match the test method names in
* {@link EnabledForJreRangeIntegrationTests}.
@@ -39,6 +45,8 @@
*/
class EnabledForJreRangeConditionTests extends AbstractExecutionConditionTests {
+ private static final String JAVA_VERSION = System.getProperty("java.version");
+
@Override
protected ExecutionCondition getExecutionCondition() {
return new EnabledForJreRangeCondition();
@@ -66,63 +74,283 @@ void enabledBecauseAnnotationIsNotPresent() {
void defaultValues() {
assertThatExceptionOfType(PreconditionViolationException.class)//
.isThrownBy(this::evaluateCondition)//
- .withMessageContaining("You must declare a non-default value for min or max in @EnabledForJreRange");
+ .withMessage(
+ "You must declare a non-default value for the minimum or maximum value in @EnabledForJreRange");
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#effectiveJreDefaultValues()
+ */
+ @Test
+ void effectiveJreDefaultValues() {
+ defaultValues();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#effectiveVersionDefaultValues()
+ */
+ @Test
+ void effectiveVersionDefaultValues() {
+ defaultValues();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#min8()
+ */
+ @Test
+ void min8() {
+ defaultValues();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minVersion8()
+ */
+ @Test
+ void minVersion8() {
+ defaultValues();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#maxOther()
+ */
+ @Test
+ void maxOther() {
+ defaultValues();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#maxVersionMaxInteger()
+ */
+ @Test
+ void maxVersionMaxInteger() {
+ defaultValues();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minVersion7()
+ */
+ @Test
+ void minVersion7() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage("@EnabledForJreRange's minVersion [7] must be greater than or equal to 8");
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#maxVersion7()
+ */
+ @Test
+ void maxVersion7() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage("@EnabledForJreRange's maxVersion [7] must be greater than or equal to 8");
}
/**
- * @see EnabledForJreRangeIntegrationTests#java17()
+ * @see EnabledForJreRangeIntegrationTests#minAndMinVersion()
*/
@Test
- void java17() {
+ void minAndMinVersion() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage(
+ "@EnabledForJreRange's minimum value must be configured with either a JRE enum constant or numeric version, but not both");
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#maxAndMaxVersion()
+ */
+ @Test
+ void maxAndMaxVersion() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage(
+ "@EnabledForJreRange's maximum value must be configured with either a JRE enum constant or numeric version, but not both");
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minGreaterThanMax()
+ */
+ @Test
+ void minGreaterThanMax() {
+ assertThatExceptionOfType(PreconditionViolationException.class)//
+ .isThrownBy(this::evaluateCondition)//
+ .withMessage(
+ "@EnabledForJreRange's minimum value [21] must be less than or equal to its maximum value [11]");
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minGreaterThanMaxVersion()
+ */
+ @Test
+ void minGreaterThanMaxVersion() {
+ minGreaterThanMax();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minVersionGreaterThanMaxVersion()
+ */
+ @Test
+ void minVersionGreaterThanMaxVersion() {
+ minGreaterThanMax();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minVersionGreaterThanMax()
+ */
+ @Test
+ void minVersionGreaterThanMax() {
+ minGreaterThanMax();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#min20()
+ */
+ @Test
+ void min20() {
evaluateCondition();
- assertEnabledOnCurrentJreIf(onJava17());
+ assertEnabledOnCurrentJreIf(!onJava19());
+ assertEnabledOnCurrentJreIf(onJava20() || onJava21() || onJava22() || onJava23());
}
/**
- * @see EnabledForJreRangeIntegrationTests#java18to19()
+ * @see EnabledForJreRangeIntegrationTests#minVersion20()
*/
@Test
- void java18to19() {
+ void minVersion20() {
+ min20();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#max21()
+ */
+ @Test
+ void max21() {
evaluateCondition();
- assertEnabledOnCurrentJreIf(onJava18() || onJava19());
+ assertEnabledOnCurrentJreIf(
+ onJava8() || onJava9() || onJava10() || onJava11() || onJava12() || onJava13() || onJava14() || onJava15()
+ || onJava16() || onJava17() || onJava18() || onJava19() || onJava20() || onJava21());
}
/**
- * @see EnabledForJreRangeIntegrationTests#javaMax18()
+ * @see EnabledForJreRangeIntegrationTests#maxVersion21()
*/
@Test
- void javaMax18() {
+ void maxVersion21() {
+ max21();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#min8Max21()
+ */
+ @Test
+ void min8Max21() {
+ max21();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#min17Max17()
+ */
+ @Test
+ void min17Max17() {
evaluateCondition();
- assertEnabledOnCurrentJreIf(onJava8() || onJava9() || onJava10() || onJava11() || onJava12() || onJava13()
- || onJava14() || onJava15() || onJava16() || onJava17() || onJava18());
+ assertEnabledOnCurrentJreIf(onJava17());
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#min17MaxVersion17()
+ */
+ @Test
+ void min17MaxVersion17() {
+ min17Max17();
}
/**
- * @see EnabledForJreRangeIntegrationTests#javaMin18()
+ * @see EnabledForJreRangeIntegrationTests#minVersion17Max17()
*/
@Test
- void javaMin18() {
+ void minVersion17Max17() {
+ min17Max17();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minVersion17MaxVersion17()
+ */
+ @Test
+ void minVersion17MaxVersion17() {
+ min17Max17();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#min20Max21()
+ */
+ @Test
+ void min20Max21() {
+ evaluateCondition();
+ assertEnabledOnCurrentJreIf(!(onJava19() || onJava22()));
+ assertEnabledOnCurrentJreIf(onJava20() || onJava21());
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#min20MaxVersion21()
+ */
+ @Test
+ void min20MaxVersion21() {
+ min20Max21();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minVersion20Max21()
+ */
+ @Test
+ void minVersion20Max21() {
+ min20Max21();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minVersion20MaxVersion21()
+ */
+ @Test
+ void minVersion20MaxVersion21() {
+ min20Max21();
+ }
+
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minVersion17MaxVersionMaxInteger()
+ */
+ @Test
+ void minVersion17MaxVersionMaxInteger() {
evaluateCondition();
- assertEnabledOnCurrentJreIf(!(onJava17()));
+ assertEnabledOnCurrentJreIf(!onJava16());
+ assertEnabledOnCurrentJreIf(onJava17() || onJava18() || onJava19() || onJava20() || onJava21() || onJava22()
+ || onJava23() || onJava24() || onJava25());
}
/**
- * @see EnabledForJreRangeIntegrationTests#other()
+ * @see EnabledForJreRangeIntegrationTests#minOtherMaxOther()
*/
@Test
- void other() {
+ void minOtherMaxOther() {
evaluateCondition();
assertEnabledOnCurrentJreIf(!onKnownVersion());
}
+ /**
+ * @see EnabledForJreRangeIntegrationTests#minMaxIntegerMaxMaxInteger()
+ */
+ @Test
+ void minMaxIntegerMaxMaxInteger() {
+ minOtherMaxOther();
+ }
+
private void assertEnabledOnCurrentJreIf(boolean condition) {
if (condition) {
assertEnabled();
- assertReasonContains("Enabled on JRE version: " + System.getProperty("java.version"));
+ assertReasonContains("Enabled on JRE version: " + JAVA_VERSION);
}
else {
assertDisabled();
- assertReasonContains("Disabled on JRE version: " + System.getProperty("java.version"));
+ assertReasonContains("Disabled on JRE version: " + JAVA_VERSION);
}
}
diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeIntegrationTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeIntegrationTests.java
index 8ce5f2bc4329..9c651b8af2b2 100644
--- a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeIntegrationTests.java
+++ b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeIntegrationTests.java
@@ -13,9 +13,12 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.condition.JRE.JAVA_11;
import static org.junit.jupiter.api.condition.JRE.JAVA_17;
import static org.junit.jupiter.api.condition.JRE.JAVA_18;
-import static org.junit.jupiter.api.condition.JRE.JAVA_19;
+import static org.junit.jupiter.api.condition.JRE.JAVA_20;
+import static org.junit.jupiter.api.condition.JRE.JAVA_21;
+import static org.junit.jupiter.api.condition.JRE.JAVA_8;
import static org.junit.jupiter.api.condition.JRE.OTHER;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava10;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava11;
@@ -27,6 +30,10 @@
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava17;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava18;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava19;
+import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava20;
+import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava21;
+import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava22;
+import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava23;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava8;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion;
@@ -35,12 +42,14 @@
import org.junit.jupiter.api.Test;
/**
- * Integration tests for {@link EnabledForJreRange}.
+ * Integration tests for {@link EnabledForJreRange @EnabledForJreRange}.
*
* @since 5.6
*/
class EnabledForJreRangeIntegrationTests {
+ private static final JRE CURRENT_JRE = JRE.currentJre();
+
@Test
@Disabled("Only used in a unit test via reflection")
void enabledBecauseAnnotationIsNotPresent() {
@@ -53,39 +62,212 @@ void defaultValues() {
fail("should result in a configuration exception");
}
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(min = JAVA_8, max = OTHER)
+ void effectiveJreDefaultValues() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(minVersion = 8, maxVersion = Integer.MAX_VALUE)
+ void effectiveVersionDefaultValues() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(min = JAVA_8)
+ void min8() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(minVersion = 8)
+ void minVersion8() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(max = OTHER)
+ void maxOther() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(maxVersion = Integer.MAX_VALUE)
+ void maxVersionMaxInteger() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(minVersion = 7)
+ void minVersion7() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(maxVersion = 7)
+ void maxVersion7() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(min = JAVA_18, minVersion = 21)
+ void minAndMinVersion() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(max = JAVA_18, maxVersion = 21)
+ void maxAndMaxVersion() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(min = JAVA_21, max = JAVA_11)
+ void minGreaterThanMax() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(min = JAVA_21, maxVersion = 11)
+ void minGreaterThanMaxVersion() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(minVersion = 21, maxVersion = 11)
+ void minVersionGreaterThanMaxVersion() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @Disabled("Only used in a unit test via reflection")
+ @EnabledForJreRange(minVersion = 21, max = JAVA_11)
+ void minVersionGreaterThanMax() {
+ fail("should result in a configuration exception");
+ }
+
+ @Test
+ @EnabledForJreRange(min = JAVA_20)
+ void min20() {
+ assertTrue(onKnownVersion());
+ assertTrue(JRE.currentVersionNumber() >= 20);
+ assertTrue(CURRENT_JRE.compareTo(JAVA_20) >= 0);
+ assertTrue(CURRENT_JRE.version() >= 20);
+ assertFalse(onJava19());
+ }
+
+ @Test
+ @EnabledForJreRange(minVersion = 20)
+ void minVersion20() {
+ min20();
+ }
+
+ @Test
+ @EnabledForJreRange(max = JAVA_21)
+ void max21() {
+ assertTrue(onKnownVersion());
+ assertTrue(JRE.currentVersionNumber() <= 21);
+ assertTrue(CURRENT_JRE.compareTo(JAVA_21) <= 0);
+ assertTrue(CURRENT_JRE.version() <= 21);
+
+ assertTrue(onJava8() || onJava9() || onJava10() || onJava11() || onJava12() || onJava13() || onJava14()
+ || onJava15() || onJava16() || onJava17() || onJava18() || onJava19() || onJava20() || onJava21());
+ assertFalse(onJava22());
+ }
+
+ @Test
+ @EnabledForJreRange(maxVersion = 21)
+ void maxVersion21() {
+ max21();
+ }
+
+ @Test
+ @EnabledForJreRange(min = JAVA_8, max = JAVA_21)
+ void min8Max21() {
+ max21();
+ }
+
@Test
@EnabledForJreRange(min = JAVA_17, max = JAVA_17)
- void java17() {
+ void min17Max17() {
assertTrue(onJava17());
}
@Test
- @EnabledForJreRange(min = JAVA_18, max = JAVA_19)
- void java18to19() {
- assertTrue(onJava18() || onJava19());
- assertFalse(onJava17());
+ @EnabledForJreRange(min = JAVA_17, maxVersion = 17)
+ void min17MaxVersion17() {
+ min17Max17();
}
@Test
- @EnabledForJreRange(max = JAVA_18)
- void javaMax18() {
- assertTrue(onJava8() || onJava9() || onJava10() || onJava11() || onJava12() || onJava13() || onJava14()
- || onJava15() || onJava16() || onJava17() || onJava18());
- assertFalse(onJava19());
+ @EnabledForJreRange(minVersion = 17, max = JAVA_17)
+ void minVersion17Max17() {
+ min17Max17();
}
@Test
- @EnabledForJreRange(min = JAVA_18)
- void javaMin18() {
+ @EnabledForJreRange(minVersion = 17, maxVersion = 17)
+ void minVersion17MaxVersion17() {
+ min17Max17();
+ }
+
+ @Test
+ @EnabledForJreRange(min = JAVA_20, max = JAVA_21)
+ void min20Max21() {
+ assertTrue(onJava20() || onJava21());
+ assertFalse(onJava17() || onJava23());
+ }
+
+ @Test
+ @EnabledForJreRange(min = JAVA_20, maxVersion = 21)
+ void min20MaxVersion21() {
+ min20Max21();
+ }
+
+ @Test
+ @EnabledForJreRange(minVersion = 20, max = JAVA_21)
+ void minVersion20Max21() {
+ min20Max21();
+ }
+
+ @Test
+ @EnabledForJreRange(minVersion = 20, maxVersion = 21)
+ void minVersion20MaxVersion21() {
+ min20Max21();
+ }
+
+ @Test
+ @EnabledForJreRange(minVersion = 17, maxVersion = Integer.MAX_VALUE)
+ void minVersion17MaxVersionMaxInteger() {
assertTrue(onKnownVersion());
- assertTrue(JRE.currentVersion().compareTo(JAVA_18) >= 0);
- assertFalse(onJava17());
+ assertTrue(JRE.currentVersionNumber() >= 17);
+ assertTrue(JRE.currentVersionNumber() <= Integer.MAX_VALUE);
}
@Test
@EnabledForJreRange(min = OTHER, max = OTHER)
- void other() {
+ void minOtherMaxOther() {
assertFalse(onKnownVersion());
}
+ @Test
+ @EnabledForJreRange(minVersion = Integer.MAX_VALUE, maxVersion = Integer.MAX_VALUE)
+ void minMaxIntegerMaxMaxInteger() {
+ minOtherMaxOther();
+ }
+
}
diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/JRETests.java b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/JRETests.java
index 548df968e8cc..6e96da89f82d 100644
--- a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/JRETests.java
+++ b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/JRETests.java
@@ -10,13 +10,15 @@
package org.junit.jupiter.api.condition;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.condition.JRE.JAVA_17;
import static org.junit.jupiter.api.condition.JRE.JAVA_18;
import static org.junit.jupiter.api.condition.JRE.JAVA_19;
import static org.junit.jupiter.api.condition.JRE.JAVA_20;
import static org.junit.jupiter.api.condition.JRE.JAVA_21;
import static org.junit.jupiter.api.condition.JRE.JAVA_22;
+import static org.junit.jupiter.api.condition.JRE.JAVA_23;
+import static org.junit.jupiter.api.condition.JRE.JAVA_24;
import static org.junit.jupiter.api.condition.JRE.OTHER;
import org.junit.jupiter.api.Test;
@@ -28,45 +30,123 @@
*/
public class JRETests {
+ private static final JRE CURRENT_JRE = JRE.currentJre();
+
@Test
@EnabledOnJre(JAVA_17)
- void java17() {
- assertEquals(JAVA_17, JRE.currentVersion());
+ void jre17() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(JAVA_17);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(17);
}
@Test
@EnabledOnJre(JAVA_18)
- void java18() {
- assertEquals(JAVA_18, JRE.currentVersion());
+ void jre18() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(JAVA_18);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(18);
}
@Test
@EnabledOnJre(JAVA_19)
- void java19() {
- assertEquals(JAVA_19, JRE.currentVersion());
+ void jre19() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(JAVA_19);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(19);
}
@Test
@EnabledOnJre(JAVA_20)
- void java20() {
- assertEquals(JAVA_20, JRE.currentVersion());
+ void jre20() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(JAVA_20);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(20);
}
@Test
@EnabledOnJre(JAVA_21)
- void java21() {
- assertEquals(JAVA_21, JRE.currentVersion());
+ void jre21() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(JAVA_21);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(21);
}
@Test
@EnabledOnJre(JAVA_22)
- void java22() {
- assertEquals(JAVA_22, JRE.currentVersion());
+ void jre22() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(JAVA_21);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(22);
+ }
+
+ @Test
+ @EnabledOnJre(JAVA_23)
+ void jre23() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(JAVA_23);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(23);
+ }
+
+ @Test
+ @EnabledOnJre(JAVA_24)
+ void jre24() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(JAVA_24);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(24);
+ }
+
+ @Test
+ @EnabledOnJre(versions = 17)
+ void version17() {
+ jre17();
+ }
+
+ @Test
+ @EnabledOnJre(versions = 18)
+ void version18() {
+ jre18();
+ }
+
+ @Test
+ @EnabledOnJre(versions = 19)
+ void version19() {
+ jre19();
+ }
+
+ @Test
+ @EnabledOnJre(versions = 20)
+ void version20() {
+ jre20();
+ }
+
+ @Test
+ @EnabledOnJre(versions = 21)
+ void version21() {
+ jre21();
+ }
+
+ @Test
+ @EnabledOnJre(versions = 22)
+ void version22() {
+ jre22();
+ }
+
+ @Test
+ @EnabledOnJre(versions = 23)
+ void version23() {
+ jre23();
+ }
+
+ @Test
+ @EnabledOnJre(versions = 24)
+ void version24() {
+ jre24();
}
@Test
@EnabledOnJre(OTHER)
- void other() {
- assertEquals(OTHER, JRE.currentVersion());
+ void jreOther() {
+ assertThat(CURRENT_JRE).as("current version").isEqualTo(OTHER);
+ assertThat(CURRENT_JRE.version()).as("current feature version").isEqualTo(Integer.MAX_VALUE);
}
+
+ @Test
+ @EnabledOnJre(versions = Integer.MAX_VALUE)
+ void versionMaxInteger() {
+ jreOther();
+ }
+
}
diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java
index 417bb8119906..5c35fa41b844 100644
--- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java
+++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java
@@ -51,7 +51,7 @@ void java_8(@FilePrefix("maven") OutputFiles outputFiles) throws Exception {
@Test
void java_default(@FilePrefix("maven") OutputFiles outputFiles) throws Exception {
- var actualLines = execute(currentJdkHome(), outputFiles, MavenEnvVars.forJre(JRE.currentVersion()));
+ var actualLines = execute(currentJdkHome(), outputFiles, MavenEnvVars.forJre(JRE.currentJre()));
assertTrue(actualLines.contains("[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 1"));
}
diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MultiReleaseJarTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MultiReleaseJarTests.java
index 4326fa6fa7c9..035a4d5fcdae 100644
--- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MultiReleaseJarTests.java
+++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MultiReleaseJarTests.java
@@ -77,7 +77,7 @@ void checkDefault(@TempDir Path workspace, @FilePrefix("maven") OutputFiles outp
.addArguments("-Dsnapshot.repo.url=" + mavenRepoProxy.getBaseUri()) //
.addArguments("--update-snapshots", "--show-version", "--errors", "--batch-mode") //
.addArguments("test") //
- .putEnvironment(MavenEnvVars.forJre(JRE.currentVersion())) //
+ .putEnvironment(MavenEnvVars.forJre(JRE.currentJre())) //
.redirectOutput(outputFiles) //
.startAndWait();
diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/UnalignedClasspathTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/UnalignedClasspathTests.java
index 7869a3d59186..62ca57d144f2 100644
--- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/UnalignedClasspathTests.java
+++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/UnalignedClasspathTests.java
@@ -69,7 +69,7 @@ void verifyErrorMessageForUnalignedClasspath(JRE jre, Path javaHome, @TempDir Pa
static Stream This constant is used by JUnit as a default configuration value but is
* not intended to be used by users.
*
- * This constant returns {@code -1} for its {@link #version() version}.
+ * This constant returns {@code -1} for its {@linkplain #version() version}.
*
* @since 5.12
*/
@@ -76,7 +76,7 @@ public enum JRE {
--%>@endfor
*
* This constant returns {@link Integer#MAX_VALUE} for its
- * {@link #version() version}.
+ * {@linkplain #version() version}.
*/
OTHER(Integer.MAX_VALUE);
From a3716e6d351251d24c5027c1f744dc02649d91b4 Mon Sep 17 00:00:00 2001
From: Sam Brannen <104798+sbrannen@users.noreply.github.com>
Date: Mon, 3 Feb 2025 11:50:03 +0100
Subject: [PATCH 08/14] Set undefined JRE to UNDEFINED instead of null
---
.../main/org/junit/jupiter/api/condition/JRE.java.jte | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte b/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte
index 63eb43d266ed..2287c7dc7ba3 100644
--- a/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte
+++ b/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte
@@ -120,8 +120,7 @@ public enum JRE {
private static JRE determineCurrentJre(int currentVersion) {
switch (currentVersion) {
case UNDEFINED_VERSION:
- // null signals that the current JRE version is undefined.
- return null;<%--
+ return UNDEFINED;<%--
--%>@for(var jre : jres)
case ${jre.getVersion()}:
return JAVA_${jre.getVersion()};<%--
@@ -157,7 +156,7 @@ public enum JRE {
/**
* @return {@code true} if this {@code JRE} is known to be the
* Java Runtime Environment version for the currently executing JVM or if
- * the version is {@link #OTHER}
+ * the version is {@link #OTHER} or {@link #UNDEFINED}
*
* @see #currentJre()
* @see #currentVersionNumber()
@@ -168,8 +167,7 @@ public enum JRE {
/**
* @return the {@link JRE} for the currently executing JVM, potentially
- * {@link #OTHER} or {@code null} if the current JVM version could not be
- * determined
+ * {@link #OTHER} or {@link #UNDEFINED}
*
* @since 5.7
* @see #currentVersionNumber()
@@ -183,8 +181,7 @@ public enum JRE {
/**
* @return the {@link JRE} for the currently executing JVM, potentially
- * {@link #OTHER} or {@code null} if the current JVM version could not be
- * determined
+ * {@link #OTHER} or {@link #UNDEFINED}
*
* @since 5.12
* @see #currentVersionNumber()
From 7c60b6fa62bec1ba9ec70fb4e4d78e632019a6b9 Mon Sep 17 00:00:00 2001
From: Sam Brannen <104798+sbrannen@users.noreply.github.com>
Date: Mon, 3 Feb 2025 11:56:52 +0100
Subject: [PATCH 09/14] Introduce JRE.MINIMUM_VERSION constant
---
.../api/condition/AbstractJreCondition.java | 6 +++---
.../EnabledForJreRangeCondition.java | 19 ++++++++++---------
.../junit/jupiter/api/condition/JRE.java.jte | 2 ++
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java
index 35bf1c956c90..4f42ff1915f2 100644
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java
@@ -44,9 +44,9 @@ protected void validateVersions(JRE[] jres, int[] versions) {
() -> "JRE.UNDEFINED is not supported in @" + this.annotationName);
}
for (int version : versions) {
- Preconditions.condition(version >= 8,
- () -> String.format("Version [%d] in @%s must be greater than or equal to 8", version,
- this.annotationName));
+ Preconditions.condition(version >= JRE.MINIMUM_VERSION,
+ () -> String.format("Version [%d] in @%s must be greater than or equal to %d", version,
+ this.annotationName, JRE.MINIMUM_VERSION));
}
}
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.java
index 754523fb9b5e..e6a77c2006af 100644
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.java
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRangeCondition.java
@@ -52,12 +52,12 @@ static boolean isCurrentVersionWithinRange(String annotationName, JRE minJre, JR
annotationName));
// Users must supply valid values for minVersion and maxVersion.
- Preconditions.condition(!minVersionSet || (minVersion >= 8),
- () -> String.format("@%s's minVersion [%d] must be greater than or equal to 8", annotationName,
- minVersion));
- Preconditions.condition(!maxVersionSet || (maxVersion >= 8),
- () -> String.format("@%s's maxVersion [%d] must be greater than or equal to 8", annotationName,
- maxVersion));
+ Preconditions.condition(!minVersionSet || (minVersion >= JRE.MINIMUM_VERSION),
+ () -> String.format("@%s's minVersion [%d] must be greater than or equal to %d", annotationName, minVersion,
+ JRE.MINIMUM_VERSION));
+ Preconditions.condition(!maxVersionSet || (maxVersion >= JRE.MINIMUM_VERSION),
+ () -> String.format("@%s's maxVersion [%d] must be greater than or equal to %d", annotationName, maxVersion,
+ JRE.MINIMUM_VERSION));
// Now that we have checked the basic preconditions, we need to ensure that we are
// using valid JRE enum constants.
@@ -72,10 +72,11 @@ static boolean isCurrentVersionWithinRange(String annotationName, JRE minJre, JR
int max = (maxVersionSet ? maxVersion : maxJre.version());
// Finally, we need to validate the effective minimum and maximum values.
- Preconditions.condition((min != 8 || max != Integer.MAX_VALUE),
+ Preconditions.condition((min != JRE.MINIMUM_VERSION || max != Integer.MAX_VALUE),
() -> "You must declare a non-default value for the minimum or maximum value in @" + annotationName);
- Preconditions.condition(min >= 8,
- () -> String.format("@%s's minimum value [%d] must greater than or equal to 8", annotationName, min));
+ Preconditions.condition(min >= JRE.MINIMUM_VERSION,
+ () -> String.format("@%s's minimum value [%d] must greater than or equal to %d", annotationName, min,
+ JRE.MINIMUM_VERSION));
Preconditions.condition(min <= max,
() -> String.format("@%s's minimum value [%d] must be less than or equal to its maximum value [%d]",
annotationName, min, max));
diff --git a/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte b/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte
index 2287c7dc7ba3..d1ac8a5aedec 100644
--- a/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte
+++ b/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte
@@ -82,6 +82,8 @@ public enum JRE {
static final int UNDEFINED_VERSION = -1;
+ static final int MINIMUM_VERSION = 8;
+
private static final Logger logger = LoggerFactory.getLogger(JRE.class);
private static final int CURRENT_VERSION = determineCurrentVersion();
From e696c981b301f30043c495b62010f74e746580b1 Mon Sep 17 00:00:00 2001
From: Sam Brannen <104798+sbrannen@users.noreply.github.com>
Date: Mon, 3 Feb 2025 12:07:02 +0100
Subject: [PATCH 10/14] Extract common functionality to
AbstractJreCondition.validatedVersions()
---
.../api/condition/AbstractJreCondition.java | 27 ++++++++++++-------
.../api/condition/DisabledOnJreCondition.java | 9 +------
.../api/condition/EnabledOnJreCondition.java | 9 +------
3 files changed, 19 insertions(+), 26 deletions(-)
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java
index 4f42ff1915f2..bb00e5af5a50 100644
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java
@@ -11,7 +11,9 @@
package org.junit.jupiter.api.condition;
import java.lang.annotation.Annotation;
+import java.util.Arrays;
import java.util.function.Function;
+import java.util.stream.IntStream;
import org.junit.platform.commons.util.Preconditions;
@@ -36,18 +38,23 @@ abstract class AbstractJreCondition extends BooleanExecuti
this.annotationName = annotationType.getSimpleName();
}
- protected void validateVersions(JRE[] jres, int[] versions) {
+ IntStream validatedVersions(JRE[] jres, int[] versions) {
Preconditions.condition(jres.length > 0 || versions.length > 0,
() -> "You must declare at least one JRE or version in @" + this.annotationName);
- for (JRE jre : jres) {
- Preconditions.condition(jre != JRE.UNDEFINED,
- () -> "JRE.UNDEFINED is not supported in @" + this.annotationName);
- }
- for (int version : versions) {
- Preconditions.condition(version >= JRE.MINIMUM_VERSION,
- () -> String.format("Version [%d] in @%s must be greater than or equal to %d", version,
- this.annotationName, JRE.MINIMUM_VERSION));
- }
+
+ return IntStream.concat(//
+ Arrays.stream(jres).mapToInt(jre -> {
+ Preconditions.condition(jre != JRE.UNDEFINED,
+ () -> "JRE.UNDEFINED is not supported in @" + this.annotationName);
+ return jre.version();
+ }), //
+ Arrays.stream(versions).map(version -> {
+ Preconditions.condition(version >= JRE.MINIMUM_VERSION,
+ () -> String.format("Version [%d] in @%s must be greater than or equal to %d", version,
+ this.annotationName, JRE.MINIMUM_VERSION));
+ return version;
+ })//
+ );
}
}
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJreCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJreCondition.java
index f2398f6faefa..149f3744f478 100644
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJreCondition.java
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJreCondition.java
@@ -10,9 +10,6 @@
package org.junit.jupiter.api.condition;
-import java.util.Arrays;
-import java.util.stream.IntStream;
-
import org.junit.jupiter.api.extension.ExecutionCondition;
/**
@@ -29,11 +26,7 @@ class DisabledOnJreCondition extends AbstractJreCondition