diff --git a/documentation/src/test/java/example/ConditionalTestExecutionDemo.java b/documentation/src/test/java/example/ConditionalTestExecutionDemo.java index 5d9e68eaa5a4..f63f4aedf7a7 100644 --- a/documentation/src/test/java/example/ConditionalTestExecutionDemo.java +++ b/documentation/src/test/java/example/ConditionalTestExecutionDemo.java @@ -12,6 +12,8 @@ import static org.junit.jupiter.api.condition.JRE.JAVA_10; 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_8; import static org.junit.jupiter.api.condition.JRE.JAVA_9; import static org.junit.jupiter.api.condition.OS.LINUX; @@ -23,6 +25,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledForJreRange; import org.junit.jupiter.api.condition.DisabledIf; @@ -38,6 +41,7 @@ import org.junit.jupiter.api.condition.EnabledInNativeImage; import org.junit.jupiter.api.condition.EnabledOnJre; import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.JRE; class ConditionalTestExecutionDemo { @@ -99,6 +103,16 @@ void notOnNewMacs() { } // end::user_guide_architecture[] + @Test + @EnabledOnJre(value = { JAVA_17, JAVA_18 }, versions = { 20, 21 }) + void onJava17or18or20or21() { + } + + @Test + @EnabledOnJre(versions = 21) + void onlyOnJava21() { + } + // tag::user_guide_jre[] @Test @EnabledOnJre(JAVA_8) @@ -124,6 +138,45 @@ void fromJava9toCurrentJavaFeatureNumber() { // ... } + @Test + @EnabledForJreRange(minVersion = 10) + void fromJava10toCurrentJavaFeatureNumber() { + // ... + } + + @Test + @EnabledForJreRange(minVersion = 25) + void fromJava25toCurrentJavaFeatureNumber() { + // ... + } + + @Disabled("DEMO: intended to fail") + @Test + @EnabledForJreRange(minVersion = 99, max = JRE.JAVA_17) + void fromJava99toJava17() { + // ... + } + + @Disabled("DEMO: intended to fail") + @Test + @EnabledForJreRange(min = JAVA_11, minVersion = 10) + void competingJreAndMinFeatureVersions() { + // ... + } + + @Disabled("DEMO: intended to fail") + @Test + @EnabledForJreRange(max = JAVA_11, maxVersion = 10) + void competingJreAndMaxFeatureVersions() { + // ... + } + + @Test + @EnabledForJreRange(minVersion = 10, maxVersion = 25) + void fromJava17to25() { + // ... + } + @Test @EnabledForJreRange(max = JAVA_11) void fromJava8To11() { diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRange.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRange.java index fc96d82118b0..26744999db46 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRange.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRange.java @@ -10,6 +10,7 @@ package org.junit.jupiter.api.condition; +import static org.apiguardian.api.API.Status.EXPERIMENTAL; import static org.apiguardian.api.API.Status.STABLE; import java.lang.annotation.Documented; @@ -24,7 +25,11 @@ /** * {@code @DisabledForJreRange} is used to signal that the annotated test class * or test method is disabled for a specific range of Java Runtime - * Environment (JRE) versions from {@link #min} to {@link #max}. + * Environment (JRE) versions. + * + *
Version ranges can be specified as {@link JRE} enum constants via {@link #min} + * and {@link #max} or as integers via {@link #minFeatureVersion} and + * {@link #maxFeatureVersion}. * *
When applied at the class level, all test methods within that class will * be disabled on the same specified JRE versions. @@ -82,29 +87,75 @@ 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#JAVA_8 JAVA_8}, as this is the lowest supported + * JRE version. * * @see JRE + * @see #minVersion() */ JRE min() default JRE.JAVA_8; /** - * 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. + * + *
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#OTHER OTHER}, as this will always be the highest * possible version. * * @see JRE + * @see #maxVersion() */ JRE max() default JRE.OTHER; + /** + * 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()
+ */
+ @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..1f74ab51749a 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
@@ -31,13 +31,25 @@ 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..44c60317732f 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
@@ -32,9 +32,12 @@ 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 #minFeatureVersion} and
+ * {@link #maxFeatureVersion}.
*
* When applied at the class level, all test methods within that class will
* be enabled on the same specified JRE versions.
@@ -82,29 +87,75 @@
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#JAVA_8 JAVA_8}, as this is the lowest supported
+ * JRE version.
*
* @see JRE
+ * @see #minVersion()
*/
JRE min() default JRE.JAVA_8;
/**
- * 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.
+ *
+ * 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#OTHER OTHER}, as this will always be the highest
* possible version.
*
* @see JRE
+ * @see #maxVersion()
*/
JRE max() default JRE.OTHER;
+ /**
+ * 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()
+ */
+ @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..a1a8a1a5cbb4 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
@@ -31,13 +31,25 @@ 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.
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..f5e263abfeaa 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
@@ -35,9 +35,12 @@ class EnabledOnJreCondition extends BooleanExecutionCondition