Skip to content

Commit

Permalink
Backport JAVA_23 and JAVA_24 JRE constants
Browse files Browse the repository at this point in the history
Resolves #3918.
  • Loading branch information
marcphilipp committed Sep 23, 2024
1 parent 1cf2e6f commit 7b2f7c6
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
* @see #JAVA_20
* @see #JAVA_21
* @see #JAVA_22
* @see #JAVA_23
* @see #JAVA_24
* @see #OTHER
* @see EnabledOnJre
* @see DisabledOnJre
Expand Down Expand Up @@ -162,13 +164,29 @@ public enum JRE {
@API(status = STABLE, since = "5.10")
JAVA_22,

/**
* Java 23.
*
* @since 5.11
*/
@API(status = STABLE, since = "5.11")
JAVA_23,

/**
* Java 24.
*
* @since 5.11
*/
@API(status = STABLE, since = "5.11")
JAVA_24,

/**
* A JRE version other than {@link #JAVA_8}, {@link #JAVA_9},
* {@link #JAVA_10}, {@link #JAVA_11}, {@link #JAVA_12},
* {@link #JAVA_13}, {@link #JAVA_14}, {@link #JAVA_15},
* {@link #JAVA_16}, {@link #JAVA_17}, {@link #JAVA_18},
* {@link #JAVA_19}, {@link #JAVA_20}, {@link #JAVA_21}, or
* {@link #JAVA_22}.
* {@link #JAVA_19}, {@link #JAVA_20}, {@link #JAVA_21},
* {@link #JAVA_22}, {@link #JAVA_23}, or {@link #JAVA_24}.
*/
OTHER;

Expand Down Expand Up @@ -226,6 +244,10 @@ private static JRE determineCurrentVersion() {
return JAVA_21;
case 22:
return JAVA_22;
case 23:
return JAVA_23;
case 24:
return JAVA_24;
default:
return OTHER;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package org.junit.jupiter.api.condition;

public class JavaVersionPredicates {

private static final String JAVA_VERSION = System.getProperty("java.version");

static boolean onJava8() {
return JAVA_VERSION.startsWith("1.8");
}

static boolean onJava9() {
return JAVA_VERSION.startsWith("9");
}

static boolean onJava10() {
return JAVA_VERSION.startsWith("10");
}

static boolean onJava11() {
return JAVA_VERSION.startsWith("11");
}

static boolean onJava12() {
return JAVA_VERSION.startsWith("12");
}

static boolean onJava13() {
return JAVA_VERSION.startsWith("13");
}

static boolean onJava14() {
return JAVA_VERSION.startsWith("14");
}

static boolean onJava15() {
return JAVA_VERSION.startsWith("15");
}

static boolean onJava16() {
return JAVA_VERSION.startsWith("16");
}

static boolean onJava17() {
return JAVA_VERSION.startsWith("17");
}

static boolean onJava18() {
return JAVA_VERSION.startsWith("18");
}

static boolean onJava19() {
return JAVA_VERSION.startsWith("19");
}

static boolean onJava20() {
return JAVA_VERSION.startsWith("20");
}

static boolean onJava21() {
return JAVA_VERSION.startsWith("21");
}

static boolean onJava22() {
return JAVA_VERSION.startsWith("22");
}

static boolean onJava23() {
return JAVA_VERSION.startsWith("23");
}

static boolean onJava24() {
return JAVA_VERSION.startsWith("24");
}

static boolean onKnownVersion() {
return onJava8() //
|| onJava9() //
|| onJava10() //
|| onJava11() //
|| onJava12() //
|| onJava13() //
|| onJava14() //
|| onJava15() //
|| onJava16() //
|| onJava17() //
|| onJava18() //
|| onJava19() //
|| onJava20() //
|| onJava21() //
|| onJava22() //
|| onJava23() //
|| onJava24();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
package org.junit.jupiter.api.condition;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava10;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava11;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava12;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava13;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava14;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava15;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava16;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava17;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava18;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava19;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava20;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava21;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava22;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava8;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava9;
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.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.onJava8;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExecutionCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
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.EnabledOnJreIntegrationTests.onJava10;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava11;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava12;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava13;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava14;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava15;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava16;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava17;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava18;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava19;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava20;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava21;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava22;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava8;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava9;
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.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.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.onJava8;
import static org.junit.jupiter.api.condition.JavaVersionPredicates.onJava9;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava10;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava11;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava12;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava13;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava14;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava15;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava16;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava17;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava18;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava19;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava20;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava21;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava22;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava8;
import static org.junit.jupiter.api.condition.EnabledOnJreIntegrationTests.onJava9;
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.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.onJava24;
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;
import org.junit.jupiter.api.extension.ExecutionCondition;
Expand Down Expand Up @@ -216,15 +219,31 @@ void java22() {
assertDisabledOnCurrentJreIf(onJava22());
}

/**
* @see DisabledOnJreIntegrationTests#java23()
*/
@Test
void java23() {
evaluateCondition();
assertDisabledOnCurrentJreIf(onJava23());
}

/**
* @see DisabledOnJreIntegrationTests#java24()
*/
@Test
void java24() {
evaluateCondition();
assertDisabledOnCurrentJreIf(onJava24());
}

/**
* @see DisabledOnJreIntegrationTests#other()
*/
@Test
void other() {
evaluateCondition();
assertDisabledOnCurrentJreIf(
!(onJava8() || onJava9() || onJava10() || onJava11() || onJava12() || onJava13() || onJava14() || onJava15()
|| onJava16() || onJava17() || onJava18() || onJava19() || onJava20() || onJava21() || onJava22()));
assertDisabledOnCurrentJreIf(!onKnownVersion());
}

private void assertDisabledOnCurrentJreIf(boolean condition) {
Expand Down
Loading

0 comments on commit 7b2f7c6

Please sign in to comment.