diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-6.0.0-M1.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-6.0.0-M1.adoc index cae381374e60..fb2d3e95dc31 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-6.0.0-M1.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-6.0.0-M1.adoc @@ -92,6 +92,13 @@ repository on GitHub. - `InvocationInterceptor.interceptDynamicTest(Invocation, ExtensionContext)` method * The deprecated `junit.jupiter.tempdir.scope` configuration parameter is no longer supported. +* The `JRE` enum constants for `JAVA_8` to `JAVA_16` have been deprecated because they can + no longer be used at runtime since `JAVA_17` is the new baseline. Please also check for + values less than 17 used with the `minVersion` and `maxVersion` attributes of + `@EnabledForJreRange` nad `@DisabledForJreRange` or the `versions` attribute of + `@EnabledOnJre` and `@DisabledOnJre`. +* `@EnabledForJreRange` and `@DisabledForJreRange` now use `JAVA_17` as their default + `min` value. [[release-notes-6.0.0-M1-junit-jupiter-new-features-and-improvements]] ==== New Features and Improvements diff --git a/documentation/src/test/java/example/ConditionalTestExecutionDemo.java b/documentation/src/test/java/example/ConditionalTestExecutionDemo.java index ef18bb5ddff6..0bd278ddc9c1 100644 --- a/documentation/src/test/java/example/ConditionalTestExecutionDemo.java +++ b/documentation/src/test/java/example/ConditionalTestExecutionDemo.java @@ -10,10 +10,11 @@ package example; -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_21; -import static org.junit.jupiter.api.condition.JRE.JAVA_9; +import static org.junit.jupiter.api.condition.JRE.JAVA_25; import static org.junit.jupiter.api.condition.OS.LINUX; import static org.junit.jupiter.api.condition.OS.MAC; import static org.junit.jupiter.api.condition.OS.WINDOWS; @@ -113,44 +114,44 @@ void onJava17And21() { } @Test - @EnabledForJreRange(min = JAVA_9, max = JAVA_11) - void fromJava9To11() { + @EnabledForJreRange(min = JAVA_21, max = JAVA_25) + void fromJava21To25() { // ... } @Test - @EnabledForJreRange(min = JAVA_9) - void onJava9AndHigher() { + @EnabledForJreRange(min = JAVA_21) + void onJava21ndHigher() { // ... } @Test - @EnabledForJreRange(max = JAVA_11) - void fromJava8To11() { + @EnabledForJreRange(max = JAVA_18) + void fromJava17To18() { // ... } @Test - @DisabledOnJre(JAVA_9) - void notOnJava9() { + @DisabledOnJre(JAVA_19) + void notOnJava19() { // ... } @Test - @DisabledForJreRange(min = JAVA_9, max = JAVA_11) - void notFromJava9To11() { + @DisabledForJreRange(min = JAVA_17, max = JAVA_17) + void notFromJava17To19() { // ... } @Test - @DisabledForJreRange(min = JAVA_9) - void notOnJava9AndHigher() { + @DisabledForJreRange(min = JAVA_19) + void notOnJava19AndHigher() { // ... } @Test - @DisabledForJreRange(max = JAVA_11) - void notFromJava8To11() { + @DisabledForJreRange(max = JAVA_18) + void notFromJava17To18() { // ... } // end::user_guide_jre[] diff --git a/gradle/plugins/code-generator/src/main/kotlin/junitbuild/generator/GenerateJreRelatedSourceCode.kt b/gradle/plugins/code-generator/src/main/kotlin/junitbuild/generator/GenerateJreRelatedSourceCode.kt index b76ad39345d6..70f51a6d5f9f 100644 --- a/gradle/plugins/code-generator/src/main/kotlin/junitbuild/generator/GenerateJreRelatedSourceCode.kt +++ b/gradle/plugins/code-generator/src/main/kotlin/junitbuild/generator/GenerateJreRelatedSourceCode.kt @@ -57,9 +57,13 @@ abstract class GenerateJreRelatedSourceCode : DefaultTask() { mapper.registerModule(KotlinModule.Builder().build()) mapper.readValue(input, object : TypeReference>() {}) } + val minRuntimeVersion = 17 + val supportedJres = jres.filter { it.version >= minRuntimeVersion } val params = mapOf( - "jres" to jres, - "jresSortedByStringValue" to jres.sortedBy { it.version.toString() }, + "minRuntimeVersion" to minRuntimeVersion, + "allJres" to jres, + "supportedJres" to supportedJres, + "supportedJresSortedByStringValue" to supportedJres.sortedBy { it.version.toString() }, "licenseHeader" to licenseHeaderFile.asFile.get().readText() ) templates.forEach { diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreRangeCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreRangeCondition.java index 7bc7d8a0b117..df6675e8485f 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreRangeCondition.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreRangeCondition.java @@ -26,6 +26,9 @@ */ abstract class AbstractJreRangeCondition extends BooleanExecutionCondition { + private static final JRE DEFAULT_MINIMUM_JRE = JRE.JAVA_17; + private static final JRE DEFAULT_MAXIMUM_JRE = JRE.OTHER; + private final String annotationName; AbstractJreRangeCondition(Class annotationType, Function customDisabledReason) { @@ -58,17 +61,17 @@ protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int // Now that we have checked the basic preconditions, we need to ensure that we are // using valid JRE enum constants. if (!minJreSet) { - minJre = JRE.JAVA_8; + minJre = DEFAULT_MINIMUM_JRE; } if (!maxJreSet) { - maxJre = JRE.OTHER; + maxJre = DEFAULT_MAXIMUM_JRE; } int min = (minVersionSet ? minVersion : minJre.version()); int max = (maxVersionSet ? maxVersion : maxJre.version()); // Finally, we need to validate the effective minimum and maximum values. - Preconditions.condition((min != JRE.MINIMUM_VERSION || max != Integer.MAX_VALUE), + Preconditions.condition((min != DEFAULT_MINIMUM_JRE.version() || max != DEFAULT_MAXIMUM_JRE.version()), () -> "You must declare a non-default value for the minimum or maximum value in @" + this.annotationName); Preconditions.condition(min <= max, () -> String.format("@%s's minimum value [%d] must be less than or equal to its maximum value [%d]", 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 f2b077a0b2f3..a20d2d49db49 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 @@ -96,7 +96,7 @@ * {@link #minVersion() minVersion} instead. * *

Defaults to {@link JRE#UNDEFINED UNDEFINED}, which will be interpreted - * as {@link JRE#JAVA_8 JAVA_8} if the {@link #minVersion() minVersion} is + * as {@link JRE#JAVA_17 JAVA_17} if the {@link #minVersion() minVersion} is * not set. * * @see JRE diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRange.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRange.java index d60bae33d75d..b1f3d4cfd7e0 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRange.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledForJreRange.java @@ -96,7 +96,7 @@ * {@link #minVersion() minVersion} instead. * *

Defaults to {@link JRE#UNDEFINED UNDEFINED}, which will be interpreted - * as {@link JRE#JAVA_8 JAVA_8} if the {@link #minVersion() minVersion} is + * as {@link JRE#JAVA_17 JAVA_17} if the {@link #minVersion() minVersion} is * not set. * * @see JRE 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 f664e0df2e74..005f728acf0e 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 @@ -2,7 +2,8 @@ @import gg.jte.support.ForSupport @import junitbuild.generator.model.JRE -@param List jres +@param int minRuntimeVersion +@param List allJres @param String licenseHeader ${licenseHeader} package org.junit.jupiter.api.condition; @@ -11,26 +12,17 @@ import static org.apiguardian.api.API.Status.DEPRECATED; import static org.apiguardian.api.API.Status.EXPERIMENTAL; import static org.apiguardian.api.API.Status.STABLE; -import java.lang.reflect.Method; - import org.apiguardian.api.API; -import org.junit.platform.commons.logging.Logger; -import org.junit.platform.commons.logging.LoggerFactory; -import org.junit.platform.commons.support.ReflectionSupport; -import org.junit.platform.commons.util.StringUtils; /** * Enumeration of Java Runtime Environment (JRE) versions. * *

If the current JRE version can be detected but is not one of the predefined * constants in this enum, {@link #OTHER} will be considered to be the - * {@linkplain #isCurrentVersion current JRE version}. If the current JRE version - * cannot be detected — for example, if the {@code java.version} JVM system - * property is undefined — {@link #UNDEFINED} will be considered to be the - * current JRE version. + * {@linkplain #isCurrentVersion current JRE version}. * * @since 5.1 -@for(JRE jre : jres)<%-- +@for(JRE jre : allJres)<%-- --%> * @see #JAVA_${jre.getVersion()} @endfor<%-- --%> * @see #OTHER @@ -54,22 +46,30 @@ public enum JRE { */ @API(status = EXPERIMENTAL, since = "5.12") UNDEFINED(-1), -@for(var jre : jres) +@for(var jre : allJres) /** * Java ${jre.getVersion()}. - @if(jre.getSince() != null)<%-- + @if(jre.getSince() != null || jre.getVersion() < minRuntimeVersion)<%-- --%> * - * @since ${jre.getSince()} + @endif<%-- +--%>@if(jre.getSince() != null)<%-- +--%> * @since ${jre.getSince()} + @endif<%-- +--%>@if(jre.getVersion() < minRuntimeVersion)<%-- +--%> * @deprecated No longer supported at runtime; please use {@link #JAVA_17} or later @endif<%-- --%> */ - @if(jre.getSince() != null)<%-- + @if(jre.getVersion() < minRuntimeVersion)<%-- +--%>@API(status = DEPRECATED, since = "6.0") // + @Deprecated(since = "6.0", forRemoval = true) + @elseif(jre.getSince() != null)<%-- --%>@API(status = STABLE, since = "${jre.getSince()}") @endif<%-- --%>JAVA_${jre.getVersion()}(${jre.getVersion()}), @endfor /** * A JRE version other than <%-- ---%>@for(var jre : ForSupport.of(jres))<%-- +--%>@for(var jre : ForSupport.of(allJres))<%-- --%>@if(jre.isLast())or @endif<%-- --%>{@link #JAVA_${jre.get().getVersion()}}<%-- --%>@if(jre.isLast()).@else,@endif<%-- @@ -85,59 +85,13 @@ 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(); - - private static final JRE CURRENT_JRE = determineCurrentJre(CURRENT_VERSION); - - private static int determineCurrentVersion() { - String javaVersion = System.getProperty("java.version"); - boolean javaVersionIsBlank = StringUtils.isBlank(javaVersion); + static final int MINIMUM_VERSION = ${allJres.getFirst().getVersion()}; - if (javaVersionIsBlank) { - logger.debug( - () -> "JVM system property 'java.version' is undefined. It is therefore not possible to detect Java 8."); - } - - if (!javaVersionIsBlank && javaVersion.startsWith("1.8")) { - return 8; - } - - try { - // java.lang.Runtime.version() is a static method available on Java 9+ - // that returns an instance of java.lang.Runtime.Version which has the - // following method: public int major() - Method versionMethod = Runtime.class.getMethod("version"); - Object version = ReflectionSupport.invokeMethod(versionMethod, null); - Method majorMethod = version.getClass().getMethod("major"); - return (int) ReflectionSupport.invokeMethod(majorMethod, version); - } - catch (Exception ex) { - logger.debug(ex, () -> "Failed to determine the current JRE version via java.lang.Runtime.Version."); - } - - return UNDEFINED_VERSION; - } - - private static JRE determineCurrentJre(int currentVersion) { - switch (currentVersion) { - case UNDEFINED_VERSION: - return UNDEFINED;<%-- - --%>@for(var jre : jres) - case ${jre.getVersion()}: - return JAVA_${jre.getVersion()};<%-- - --%>@endfor - default: - return OTHER; - } - } + private static final int CURRENT_VERSION = Runtime.version().feature(); private final int version; - private JRE(int version) { + JRE(int version) { this.version = version; } @@ -161,18 +115,18 @@ 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} or {@link #UNDEFINED} + * the version is {@link #OTHER} * * @see #currentJre() * @see #currentVersionNumber() */ public boolean isCurrentVersion() { - return this == CURRENT_JRE; + return this == currentJre(); } /** * @return the {@link JRE} for the currently executing JVM, potentially - * {@link #OTHER} or {@link #UNDEFINED} + * {@link #OTHER} * * @since 5.7 * @see #currentVersionNumber() @@ -186,14 +140,19 @@ public enum JRE { /** * @return the {@link JRE} for the currently executing JVM, potentially - * {@link #OTHER} or {@link #UNDEFINED} + * {@link #OTHER} * * @since 5.12 * @see #currentVersionNumber() */ @API(status = STABLE, since = "5.12") public static JRE currentJre() { - return CURRENT_JRE; + return switch (CURRENT_VERSION) {<%-- + --%>@for(var jre : allJres) + case ${jre.getVersion()} -> JAVA_${jre.getVersion()};<%-- + --%>@endfor + default -> OTHER; + }; } /** 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 41db82bc794e..bf4929f61752 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 @@ -2,7 +2,7 @@ @import gg.jte.support.ForSupport @import junitbuild.generator.model.JRE -@param List jres +@param List supportedJres @param String licenseHeader ${licenseHeader} package org.junit.jupiter.api.condition; @@ -10,13 +10,13 @@ package org.junit.jupiter.api.condition; public class JavaVersionPredicates { private static final int JAVA_VERSION = Runtime.version().feature(); -@for(JRE jre : jres) +@for(JRE jre : supportedJres) static boolean onJava${jre.getVersion()}() { return JAVA_VERSION == ${jre.getVersion()}; } @endfor static boolean onKnownVersion() { - return @for(var jre : ForSupport.of(jres))onJava${jre.get().getVersion()}()@if(!jre.isLast()) // + return @for(var jre : ForSupport.of(supportedJres))onJava${jre.get().getVersion()}()@if(!jre.isLast()) // || @endif@endfor; } } 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 b6ce05e15fa6..67d8d3978950 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 @@ -1,14 +1,14 @@ @import java.util.List @import junitbuild.generator.model.JRE -@param List jres -@param List jresSortedByStringValue +@param List supportedJres +@param List supportedJresSortedByStringValue @param String licenseHeader ${licenseHeader} package org.junit.jupiter.api.condition; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@for(var jre : jresSortedByStringValue)<%-- +@for(var jre : supportedJresSortedByStringValue)<%-- --%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()}; @endfor<%-- --%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion; @@ -89,7 +89,7 @@ class DisabledOnJreConditionTests extends AbstractExecutionConditionTests { assertDisabledOnCurrentJreIf(true); assertCustomDisabledReasonIs("Disabled on every JRE"); } -@for(var jre : jres) +@for(var jre : supportedJres) /** * @see DisabledOnJreIntegrationTests#jre${jre.getVersion()}() */ @@ -99,7 +99,7 @@ class DisabledOnJreConditionTests extends AbstractExecutionConditionTests { assertDisabledOnCurrentJreIf(onJava${jre.getVersion()}()); } @endfor<%-- ---%>@for(var jre : jres) +--%>@for(var jre : supportedJres) /** * @see DisabledOnJreIntegrationTests#version${jre.getVersion()}() */ 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 509b5d47fa48..429d9d3f90ef 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 @@ -1,8 +1,9 @@ @import java.util.List @import junitbuild.generator.model.JRE -@param List jres -@param List jresSortedByStringValue +@param List allJres +@param List supportedJres +@param List supportedJresSortedByStringValue @param String licenseHeader ${licenseHeader} package org.junit.jupiter.api.condition; @@ -10,12 +11,7 @@ package org.junit.jupiter.api.condition; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -@for(var jre : jresSortedByStringValue)<%-- ---%>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)<%-- +@for(var jre : supportedJresSortedByStringValue)<%-- --%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()}; @endfor<%-- --%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion; @@ -38,40 +34,41 @@ class DisabledOnJreIntegrationTests { @Test @Disabled("Only used in a unit test via reflection") - @DisabledOnJre({}) + @DisabledOnJre void missingVersionDeclaration() { } @Test @Disabled("Only used in a unit test via reflection") - @DisabledOnJre(UNDEFINED) + @DisabledOnJre(JRE.UNDEFINED) void jreUndefined() { } @Test @Disabled("Only used in a unit test via reflection") - @DisabledOnJre(value = JAVA_17, versions = { 21, 7 }) + @DisabledOnJre(value = JRE.JAVA_17, versions = { 21, 7 }) void version7() { } + @SuppressWarnings("removal") @Test @DisabledOnJre(disabledReason = "Disabled on every JRE", value = { // -@for(var jre : jres)<%-- ---%> JAVA_${jre.getVersion()}, // +@for(var jre : allJres)<%-- +--%> JRE.JAVA_${jre.getVersion()}, // @endfor<%-- ---%> OTHER // +--%> JRE.OTHER // }) void disabledOnAllJavaVersions() { fail("should be disabled"); } -@for(var jre : jres) +@for(var jre : supportedJres) @Test - @DisabledOnJre(JAVA_${jre.getVersion()}) + @DisabledOnJre(JRE.JAVA_${jre.getVersion()}) void jre${jre.getVersion()}() { assertFalse(onJava${jre.getVersion()}()); } @endfor<%-- ---%>@for(var jre : jres) +--%>@for(var jre : supportedJres) @Test @DisabledOnJre(versions = ${jre.getVersion()}) void version${jre.getVersion()}() { @@ -79,7 +76,7 @@ class DisabledOnJreIntegrationTests { } @endfor @Test - @DisabledOnJre(OTHER) + @DisabledOnJre(JRE.OTHER) void other() { assertTrue(onKnownVersion()); } 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 9d6a1ee02021..7319b74ce364 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 @@ -1,14 +1,14 @@ @import java.util.List @import junitbuild.generator.model.JRE -@param List jres -@param List jresSortedByStringValue +@param List supportedJres +@param List supportedJresSortedByStringValue @param String licenseHeader ${licenseHeader} package org.junit.jupiter.api.condition; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@for(var jre : jresSortedByStringValue)<%-- +@for(var jre : supportedJresSortedByStringValue)<%-- --%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()}; @endfor<%-- --%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion; @@ -88,7 +88,7 @@ class EnabledOnJreConditionTests extends AbstractExecutionConditionTests { evaluateCondition(); assertEnabledOnCurrentJreIf(true); } -@for(var jre : jres) +@for(var jre : supportedJres) /** * @see EnabledOnJreIntegrationTests#jre${jre.getVersion()}() */ @@ -98,7 +98,7 @@ class EnabledOnJreConditionTests extends AbstractExecutionConditionTests { assertEnabledOnCurrentJreIf(onJava${jre.getVersion()}()); } @endfor<%-- ---%>@for(var jre : jres) +--%>@for(var jre : supportedJres) /** * @see EnabledOnJreIntegrationTests#version${jre.getVersion()}() */ 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 651345ea02b3..a1217d687b71 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 @@ -1,20 +1,16 @@ @import java.util.List @import junitbuild.generator.model.JRE -@param List jres -@param List jresSortedByStringValue +@param List allJres +@param List supportedJres +@param List supportedJresSortedByStringValue @param String licenseHeader ${licenseHeader} package org.junit.jupiter.api.condition; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -@for(var jre : jresSortedByStringValue)<%-- ---%>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)<%-- +@for(var jre : supportedJresSortedByStringValue)<%-- --%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava${jre.getVersion()}; @endfor<%-- --%>import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion; @@ -37,39 +33,40 @@ class EnabledOnJreIntegrationTests { @Test @Disabled("Only used in a unit test via reflection") - @EnabledOnJre({}) + @EnabledOnJre void missingVersionDeclaration() { } @Test @Disabled("Only used in a unit test via reflection") - @EnabledOnJre(UNDEFINED) + @EnabledOnJre(JRE.UNDEFINED) void jreUndefined() { } @Test @Disabled("Only used in a unit test via reflection") - @EnabledOnJre(value = JAVA_17, versions = { 21, 7 }) + @EnabledOnJre(value = JRE.JAVA_17, versions = { 21, 7 }) void version7() { } + @SuppressWarnings("removal") @Test @EnabledOnJre({ // -@for(var jre : jres)<%-- ---%> JAVA_${jre.getVersion()}, // +@for(var jre : allJres)<%-- +--%> JRE.JAVA_${jre.getVersion()}, // @endfor<%-- ---%> OTHER // +--%> JRE.OTHER // }) void enabledOnAllJavaVersions() { } -@for(var jre : jres) +@for(var jre : supportedJres) @Test - @EnabledOnJre(JAVA_${jre.getVersion()}) + @EnabledOnJre(JRE.JAVA_${jre.getVersion()}) void jre${jre.getVersion()}() { assertTrue(onJava${jre.getVersion()}()); } @endfor<%-- ---%>@for(var jre : jres) +--%>@for(var jre : supportedJres) @Test @EnabledOnJre(versions = ${jre.getVersion()}) void version${jre.getVersion()}() { @@ -77,7 +74,7 @@ class EnabledOnJreIntegrationTests { } @endfor @Test - @EnabledOnJre(value = OTHER, disabledReason = "Disabled on almost every JRE") + @EnabledOnJre(value = JRE.OTHER, disabledReason = "Disabled on almost every JRE") void other() { assertFalse(onKnownVersion()); } diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeConditionTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeConditionTests.java index 8703958019ed..db7a64095fd8 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeConditionTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeConditionTests.java @@ -11,18 +11,9 @@ package org.junit.jupiter.api.condition; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava10; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava11; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava12; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava13; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava14; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava15; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava16; 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.onJava8; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9; import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion; import org.junit.jupiter.api.Test; @@ -89,18 +80,18 @@ void effectiveVersionDefaultValues() { } /** - * @see DisabledForJreRangeIntegrationTests#min8() + * @see DisabledForJreRangeIntegrationTests#min17() */ @Test - void min8() { + void min17() { defaultValues(); } /** - * @see DisabledForJreRangeIntegrationTests#minVersion8() + * @see DisabledForJreRangeIntegrationTests#minVersion17() */ @Test - void minVersion8() { + void minVersion17() { defaultValues(); } @@ -131,13 +122,14 @@ void minVersion7() { } /** - * @see DisabledForJreRangeIntegrationTests#maxVersion7() + * @see DisabledForJreRangeIntegrationTests#maxVersion16() */ @Test - void maxVersion7() { + void maxVersion16() { assertThatExceptionOfType(PreconditionViolationException.class)// .isThrownBy(this::evaluateCondition)// - .withMessage("@DisabledForJreRange's maxVersion [7] must be greater than or equal to 8"); + .withMessage( + "@DisabledForJreRange's minimum value [17] must be less than or equal to its maximum value [16]"); } /** @@ -170,7 +162,7 @@ void minGreaterThanMax() { assertThatExceptionOfType(PreconditionViolationException.class)// .isThrownBy(this::evaluateCondition)// .withMessage( - "@DisabledForJreRange's minimum value [21] must be less than or equal to its maximum value [11]"); + "@DisabledForJreRange's minimum value [21] must be less than or equal to its maximum value [17]"); } /** @@ -220,8 +212,7 @@ void minVersion18() { @Test void max18() { evaluateCondition(); - assertDisabledOnCurrentJreIf(onJava8() || onJava9() || onJava10() || onJava11() || onJava12() || onJava13() - || onJava14() || onJava15() || onJava16() || onJava17() || onJava18()); + assertDisabledOnCurrentJreIf(onJava17() || onJava18()); } /** diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeIntegrationTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeIntegrationTests.java index 7d043196079f..73e974b600a8 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeIntegrationTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/DisabledForJreRangeIntegrationTests.java @@ -13,25 +13,14 @@ 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_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; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava12; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava13; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava14; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava15; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava16; 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.onJava8; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9; import static org.junit.jupiter.api.condition.JavaVersionPredicates.onKnownVersion; import org.junit.jupiter.api.Disabled; @@ -57,29 +46,29 @@ void defaultValues() { @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(min = JAVA_8, max = OTHER) + @DisabledForJreRange(min = JAVA_17, max = OTHER) void effectiveJreDefaultValues() { fail("should result in a configuration exception"); } @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(minVersion = 8, maxVersion = Integer.MAX_VALUE) + @DisabledForJreRange(minVersion = 17, maxVersion = Integer.MAX_VALUE) void effectiveVersionDefaultValues() { fail("should result in a configuration exception"); } @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(min = JAVA_8) - void min8() { + @DisabledForJreRange(min = JAVA_17) + void min17() { fail("should result in a configuration exception"); } @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(minVersion = 8) - void minVersion8() { + @DisabledForJreRange(minVersion = 17) + void minVersion17() { fail("should result in a configuration exception"); } @@ -106,8 +95,8 @@ void minVersion7() { @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(maxVersion = 7) - void maxVersion7() { + @DisabledForJreRange(maxVersion = 16) + void maxVersion16() { fail("should result in a configuration exception"); } @@ -127,28 +116,28 @@ void maxAndMaxVersion() { @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(min = JAVA_21, max = JAVA_11) + @DisabledForJreRange(min = JAVA_21, max = JAVA_17) void minGreaterThanMax() { fail("should result in a configuration exception"); } @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(min = JAVA_21, maxVersion = 11) + @DisabledForJreRange(min = JAVA_21, maxVersion = 17) void minGreaterThanMaxVersion() { fail("should result in a configuration exception"); } @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(minVersion = 21, maxVersion = 11) + @DisabledForJreRange(minVersion = 21, maxVersion = 17) void minVersionGreaterThanMaxVersion() { fail("should result in a configuration exception"); } @Test @Disabled("Only used in a unit test via reflection") - @DisabledForJreRange(minVersion = 21, max = JAVA_11) + @DisabledForJreRange(minVersion = 21, max = JAVA_17) void minVersionGreaterThanMax() { fail("should result in a configuration exception"); } @@ -169,8 +158,7 @@ void minVersion18() { @Test @DisabledForJreRange(max = JAVA_18) void max18() { - assertFalse(onJava8() || onJava9() || onJava10() || onJava11() || onJava12() || onJava13() || onJava14() - || onJava15() || onJava16() || onJava17() || onJava18()); + assertFalse(onJava17() || onJava18()); } @Test diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeConditionTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeConditionTests.java index 886af0b8e309..3b7afb076d8a 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeConditionTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/api/condition/EnabledForJreRangeConditionTests.java @@ -11,13 +11,6 @@ package org.junit.jupiter.api.condition; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava10; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava11; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava12; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava13; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava14; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava15; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava16; 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; @@ -27,8 +20,6 @@ import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava23; import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava24; import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava25; -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; import org.junit.jupiter.api.Test; @@ -95,18 +86,18 @@ void effectiveVersionDefaultValues() { } /** - * @see EnabledForJreRangeIntegrationTests#min8() + * @see EnabledForJreRangeIntegrationTests#min17() */ @Test - void min8() { + void min17() { defaultValues(); } /** - * @see EnabledForJreRangeIntegrationTests#minVersion8() + * @see EnabledForJreRangeIntegrationTests#minVersion17() */ @Test - void minVersion8() { + void minVersion17() { defaultValues(); } @@ -137,13 +128,14 @@ void minVersion7() { } /** - * @see EnabledForJreRangeIntegrationTests#maxVersion7() + * @see EnabledForJreRangeIntegrationTests#maxVersion16() */ @Test - void maxVersion7() { + void maxVersion16() { assertThatExceptionOfType(PreconditionViolationException.class)// .isThrownBy(this::evaluateCondition)// - .withMessage("@EnabledForJreRange's maxVersion [7] must be greater than or equal to 8"); + .withMessage( + "@EnabledForJreRange's minimum value [17] must be less than or equal to its maximum value [16]"); } /** @@ -176,7 +168,7 @@ 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]"); + "@EnabledForJreRange's minimum value [21] must be less than or equal to its maximum value [17]"); } /** @@ -226,9 +218,7 @@ void minVersion20() { @Test void max21() { evaluateCondition(); - assertEnabledOnCurrentJreIf( - onJava8() || onJava9() || onJava10() || onJava11() || onJava12() || onJava13() || onJava14() || onJava15() - || onJava16() || onJava17() || onJava18() || onJava19() || onJava20() || onJava21()); + assertEnabledOnCurrentJreIf(onJava17() || onJava18() || onJava19() || onJava20() || onJava21()); } /** @@ -240,10 +230,10 @@ void maxVersion21() { } /** - * @see EnabledForJreRangeIntegrationTests#min8Max21() + * @see EnabledForJreRangeIntegrationTests#min17Max21() */ @Test - void min8Max21() { + void min17Max21() { max21(); } @@ -314,10 +304,10 @@ void minVersion20MaxVersion21() { } /** - * @see EnabledForJreRangeIntegrationTests#minVersion17MaxVersionMaxInteger() + * @see EnabledForJreRangeIntegrationTests#minVersion21MaxVersionMaxInteger() */ @Test - void minVersion17MaxVersionMaxInteger() { + void minVersion21MaxVersionMaxInteger() { evaluateCondition(); assertEnabledOnCurrentJreIf(onJava17() || onJava18() || onJava19() || onJava20() || onJava21() || onJava22() || onJava23() || onJava24() || onJava25()); 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 03d33d1e2632..d1c26b36507f 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,20 +13,11 @@ 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_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; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava12; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava13; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava14; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava15; -import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava16; 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; @@ -34,8 +25,6 @@ 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; import org.junit.jupiter.api.Disabled; @@ -64,29 +53,29 @@ void defaultValues() { @Test @Disabled("Only used in a unit test via reflection") - @EnabledForJreRange(min = JAVA_8, max = OTHER) + @EnabledForJreRange(min = JAVA_17, 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) + @EnabledForJreRange(minVersion = 17, 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() { + @EnabledForJreRange(min = JAVA_17) + void min17() { fail("should result in a configuration exception"); } @Test @Disabled("Only used in a unit test via reflection") - @EnabledForJreRange(minVersion = 8) - void minVersion8() { + @EnabledForJreRange(minVersion = 17) + void minVersion17() { fail("should result in a configuration exception"); } @@ -113,8 +102,8 @@ void minVersion7() { @Test @Disabled("Only used in a unit test via reflection") - @EnabledForJreRange(maxVersion = 7) - void maxVersion7() { + @EnabledForJreRange(maxVersion = 16) + void maxVersion16() { fail("should result in a configuration exception"); } @@ -134,28 +123,28 @@ void maxAndMaxVersion() { @Test @Disabled("Only used in a unit test via reflection") - @EnabledForJreRange(min = JAVA_21, max = JAVA_11) + @EnabledForJreRange(min = JAVA_21, max = JAVA_17) 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) + @EnabledForJreRange(min = JAVA_21, maxVersion = 17) void minGreaterThanMaxVersion() { fail("should result in a configuration exception"); } @Test @Disabled("Only used in a unit test via reflection") - @EnabledForJreRange(minVersion = 21, maxVersion = 11) + @EnabledForJreRange(minVersion = 21, maxVersion = 17) 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) + @EnabledForJreRange(minVersion = 21, max = JAVA_17) void minVersionGreaterThanMax() { fail("should result in a configuration exception"); } @@ -184,8 +173,7 @@ void max21() { 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()); + assertTrue(onJava17() || onJava18() || onJava19() || onJava20() || onJava21()); assertFalse(onJava22()); } @@ -196,8 +184,8 @@ void maxVersion21() { } @Test - @EnabledForJreRange(min = JAVA_8, max = JAVA_21) - void min8Max21() { + @EnabledForJreRange(min = JAVA_17, max = JAVA_21) + void min17Max21() { max21(); } @@ -251,8 +239,8 @@ void minVersion20MaxVersion21() { } @Test - @EnabledForJreRange(minVersion = 17, maxVersion = Integer.MAX_VALUE) - void minVersion17MaxVersionMaxInteger() { + @EnabledForJreRange(minVersion = 21, maxVersion = Integer.MAX_VALUE) + void minVersion21MaxVersionMaxInteger() { assertTrue(onKnownVersion()); assertTrue(JRE.currentVersionNumber() >= 17); }