Add SystemUtils.IS_JAVA_22

- Add JavaVersion.JAVA_22
- Add missing test assertions
This commit is contained in:
Gary Gregory 2024-04-24 18:20:53 -04:00
parent bdff802a85
commit 892826578a
5 changed files with 869 additions and 209 deletions

View File

@ -58,7 +58,8 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add ArrayUtils.nullTo(T[], T[]).</action>
<action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add T ArrayUtils.arraycopy(T, int, T, int, int) fluent style.</action>
<action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add T ArrayUtils.arraycopy(T, int, int, int, Function) fluent style.</action>
<action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add T ArrayUtils.arraycopy(T, int, int, int, Supplier) fluent style.</action>
<action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_22.</action>
<action issue="LANG-1724" type="add" dev="ggregory" due-to="Gary Gregory">Add JavaVersion.JAVA_22.</action>
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Miklós Karakó, Gary Gregory">Improve Javadoc in ExceptionUtils #1136.</action>
<action type="fix" dev="ggregory" due-to="Saiharshith Karuneegar Ramesh, Gary Gregory">Fixed two non-deterministic tests in EnumUtilsTest.java #1131.</action>

View File

@ -171,6 +171,13 @@ public enum JavaVersion {
*/
JAVA_21(21, "21"),
/**
* Java 22.
*
* @since 3.15.0
*/
JAVA_22(22, "22"),
/**
* The most recent Java version. Mainly introduced to avoid to break when a new version of Java is used.
*/
@ -234,6 +241,8 @@ public enum JavaVersion {
return JAVA_20;
case "21":
return JAVA_21;
case "22":
return JAVA_22;
default:
final float v = toFloatVersion(versionStr);
if (v - 1. < 1.) { // then we need to check decimals > .9

View File

@ -1110,6 +1110,19 @@ public class SystemUtils {
*/
public static final boolean IS_JAVA_21 = getJavaVersionMatches("21");
/**
* Is {@code true} if this is Java version 22 (also 22.x versions).
* <p>
* The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
* </p>
* <p>
* This value is initialized when the class is loaded.
* </p>
*
* @since 3.15.0
*/
public static final boolean IS_JAVA_22 = getJavaVersionMatches("22");
// Operating system checks
// -----------------------------------------------------------------------
// These MUST be declared after those above as they depend on the

View File

@ -18,18 +18,6 @@
*/
package org.apache.commons.lang3;
import static org.apache.commons.lang3.JavaVersion.JAVA_0_9;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_3;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_5;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_6;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_7;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT;
import static org.apache.commons.lang3.JavaVersion.get;
import static org.apache.commons.lang3.JavaVersion.getJavaVersion;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -43,40 +31,49 @@ public class JavaVersionTest extends AbstractLangTest {
@Test
public void testAtLeast() {
assertFalse(JAVA_1_2.atLeast(JAVA_1_5), "1.2 at least 1.5 passed");
assertTrue(JAVA_1_5.atLeast(JAVA_1_2), "1.5 at least 1.2 failed");
assertFalse(JAVA_1_6.atLeast(JAVA_1_7), "1.6 at least 1.7 passed");
assertFalse(JavaVersion.JAVA_1_2.atLeast(JavaVersion.JAVA_1_5), "1.2 at least 1.5 passed");
assertTrue(JavaVersion.JAVA_1_5.atLeast(JavaVersion.JAVA_1_2), "1.5 at least 1.2 failed");
assertFalse(JavaVersion.JAVA_1_6.atLeast(JavaVersion.JAVA_1_7), "1.6 at least 1.7 passed");
assertTrue(JAVA_0_9.atLeast(JAVA_1_5), "0.9 at least 1.5 failed");
assertFalse(JAVA_0_9.atLeast(JAVA_1_6), "0.9 at least 1.6 passed");
assertTrue(JavaVersion.JAVA_0_9.atLeast(JavaVersion.JAVA_1_5), "0.9 at least 1.5 failed");
assertFalse(JavaVersion.JAVA_0_9.atLeast(JavaVersion.JAVA_1_6), "0.9 at least 1.6 passed");
}
@Test
public void testGetJavaVersion() throws Exception {
assertEquals(JAVA_0_9, get("0.9"), "0.9 failed");
assertEquals(JAVA_1_1, get("1.1"), "1.1 failed");
assertEquals(JAVA_1_2, get("1.2"), "1.2 failed");
assertEquals(JAVA_1_3, get("1.3"), "1.3 failed");
assertEquals(JAVA_1_4, get("1.4"), "1.4 failed");
assertEquals(JAVA_1_5, get("1.5"), "1.5 failed");
assertEquals(JAVA_1_6, get("1.6"), "1.6 failed");
assertEquals(JAVA_1_7, get("1.7"), "1.7 failed");
assertEquals(JAVA_1_8, get("1.8"), "1.8 failed");
assertEquals(JavaVersion.JAVA_0_9, JavaVersion.get("0.9"), "0.9 failed");
assertEquals(JavaVersion.JAVA_1_1, JavaVersion.get("1.1"), "1.1 failed");
assertEquals(JavaVersion.JAVA_1_2, JavaVersion.get("1.2"), "1.2 failed");
assertEquals(JavaVersion.JAVA_1_3, JavaVersion.get("1.3"), "1.3 failed");
assertEquals(JavaVersion.JAVA_1_4, JavaVersion.get("1.4"), "1.4 failed");
assertEquals(JavaVersion.JAVA_1_5, JavaVersion.get("1.5"), "1.5 failed");
assertEquals(JavaVersion.JAVA_1_6, JavaVersion.get("1.6"), "1.6 failed");
assertEquals(JavaVersion.JAVA_1_7, JavaVersion.get("1.7"), "1.7 failed");
assertEquals(JavaVersion.JAVA_1_8, JavaVersion.get("1.8"), "1.8 failed");
assertEquals(JavaVersion.JAVA_9, JavaVersion.get("9"));
assertEquals(JavaVersion.JAVA_10, JavaVersion.get("10"));
assertEquals(JavaVersion.JAVA_11, JavaVersion.get("11"));
assertEquals(JavaVersion.JAVA_12, JavaVersion.get("12"));
assertEquals(JavaVersion.JAVA_13, JavaVersion.get("13"));
assertEquals(JavaVersion.JAVA_14, JavaVersion.get("14"));
assertEquals(JavaVersion.JAVA_15, JavaVersion.get("15"));
assertEquals(JavaVersion.JAVA_16, JavaVersion.get("16"));
assertEquals(JavaVersion.JAVA_17, JavaVersion.get("17"));
assertEquals(JavaVersion.JAVA_18, JavaVersion.get("18"));
assertEquals(JavaVersion.JAVA_19, JavaVersion.get("19"));
assertEquals(JavaVersion.JAVA_20, JavaVersion.get("20"));
assertEquals(JavaVersion.JAVA_21, JavaVersion.get("21"));
assertEquals(JavaVersion.JAVA_22, JavaVersion.get("22"));
final int lastSupportedVersion = Integer.parseInt(JavaVersion.values()[JavaVersion.values().length - 2].toString());
for (int i = 9; i <= lastSupportedVersion; i++) {
assertEquals(JavaVersion.class.getField("JAVA_" + i).get(null), get("" + i), i + " failed");
}
assertEquals(JAVA_RECENT, get("1.10"), "1.10 failed");
// assertNull("2.10 unexpectedly worked", get("2.10"));
assertEquals(get("1.5"), getJavaVersion("1.5"), "Wrapper method failed");
assertEquals(JAVA_RECENT, get("22"), "Unhandled"); // LANG-1384
assertEquals(JavaVersion.JAVA_RECENT, JavaVersion.get("1.10"), "1.10 failed");
// assertNull("2.10 unexpectedly worked", JavaVersion.get("2.10"));
assertEquals(JavaVersion.get("1.5"), JavaVersion.getJavaVersion("1.5"), "Wrapper method failed");
assertEquals(JavaVersion.JAVA_RECENT, JavaVersion.get("23"), "Unhandled"); // LANG-1384
}
@Test
public void testToString() {
assertEquals("1.2", JAVA_1_2.toString());
assertEquals("1.2", JavaVersion.JAVA_1_2.toString());
}
}

File diff suppressed because it is too large Load Diff