From ff66cce0ca10046727e594e0beeed7924dfc7a41 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 30 May 2024 14:33:14 -0400 Subject: [PATCH] Add SystemUtils.IS_OS_MAC_OSX_SONOMA --- src/changes/changes.xml | 1 + .../java/org/apache/commons/lang3/SystemUtils.java | 13 +++++++++++++ .../org/apache/commons/lang3/SystemUtilsTest.java | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 129bb71ea..9d4e1ff0f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -67,6 +67,7 @@ The type attribute can be add,update,fix,remove. Add MethodUtils.getMethodObject(Class, String, Class...). Add null-safe Consumers.accept() and Functions.apply() #1215. Add SystemUtils.IS_OS_ANDROID. + Add SystemUtils.IS_OS_MAC_OSX_SONOMA. Improve Javadoc in ExceptionUtils #1136. Fixed two non-deterministic tests in EnumUtilsTest.java #1131. diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java index 70c9a8d2c..e712aa56f 100644 --- a/src/main/java/org/apache/commons/lang3/SystemUtils.java +++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java @@ -1506,6 +1506,19 @@ public class SystemUtils { */ public static final boolean IS_OS_MAC_OSX_VENTURA = getOsMatches("Mac OS X", "13"); + /** + * Is {@code true} if this is macOS X Sonoma. + * + *

+ * The field will return {@code false} if {@code OS_NAME} is {@code null}. + *

+ *

+ * This value is initialized when the class is loaded. + *

+ * @since 3.15.0 + */ + public static final boolean IS_OS_MAC_OSX_SONOMA = getOsMatches("Mac OS X", "14"); + /** * Is {@code true} if this is FreeBSD. * diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java index 8618d6744..ec4b04807 100644 --- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java @@ -168,6 +168,16 @@ public class SystemUtilsTest extends AbstractLangTest { assertTrue(SystemUtils.IS_OS_UNIX); assertFalse(SystemUtils.IS_OS_ANDROID); assertFalse(SystemUtils.IS_OS_WINDOWS); + final boolean macOsValues[] = { SystemUtils.IS_OS_MAC_OSX_BIG_SUR, SystemUtils.IS_OS_MAC_OSX_CATALINA, SystemUtils.IS_OS_MAC_OSX_CHEETAH, + SystemUtils.IS_OS_MAC_OSX_EL_CAPITAN, SystemUtils.IS_OS_MAC_OSX_HIGH_SIERRA, SystemUtils.IS_OS_MAC_OSX_JAGUAR, + SystemUtils.IS_OS_MAC_OSX_LEOPARD, SystemUtils.IS_OS_MAC_OSX_LION, SystemUtils.IS_OS_MAC_OSX_MAVERICKS, SystemUtils.IS_OS_MAC_OSX_MOJAVE, + SystemUtils.IS_OS_MAC_OSX_MONTEREY, SystemUtils.IS_OS_MAC_OSX_MOUNTAIN_LION, SystemUtils.IS_OS_MAC_OSX_PANTHER, + SystemUtils.IS_OS_MAC_OSX_PUMA, SystemUtils.IS_OS_MAC_OSX_SIERRA, SystemUtils.IS_OS_MAC_OSX_SNOW_LEOPARD, SystemUtils.IS_OS_MAC_OSX_SONOMA, + SystemUtils.IS_OS_MAC_OSX_TIGER, SystemUtils.IS_OS_MAC_OSX_VENTURA, SystemUtils.IS_OS_MAC_OSX_YOSEMITE }; + if (BooleanUtils.or(macOsValues)) { + // If one is true, then only one should be true. + assertTrue(BooleanUtils.xor(macOsValues)); + } } else if (osName.startsWith("OS/2")) { assertTrue(SystemUtils.IS_OS_OS2); assertFalse(SystemUtils.IS_OS_UNIX);