This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 7cb24c310 Add more tests for LocaleUtils.toLocale(String)
7cb24c310 is described below

commit 7cb24c31092e719790a0fd1ab7f29cb3c9bb6366
Author: Gary D. Gregory <[email protected]>
AuthorDate: Sun Oct 5 15:15:42 2025 -0400

    Add more tests for LocaleUtils.toLocale(String)
---
 src/main/java/org/apache/commons/lang3/LocaleUtils.java  | 13 +++++++++++++
 .../java/org/apache/commons/lang3/LocaleUtilsTest.java   | 16 ++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/LocaleUtils.java 
b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
index 4753aee1f..3b720a8c5 100644
--- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java
+++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
@@ -303,6 +303,19 @@ public static List<Locale> localeLookupList(final Locale 
locale, final Locale de
         return Collections.unmodifiableList(list);
     }
 
+    /**
+     * Creates new {@linkplain Locale} for the given country.
+     *
+     * @param country An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 
area code. See the {@linkplain Locale} class description about valid country
+     *                values.
+     * @throws NullPointerException thrown if either argument is null.
+     * @return a new new Locale for the given country.
+     * @see Locale#Locale(String, String)
+     */
+    static Locale ofCountry(final String country) {
+        return new Locale(StringUtils.EMPTY, country);
+    }
+
     /**
      * Tries to parse a Locale from the given String.
      * <p>
diff --git a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
index b5c16983d..101d02467 100644
--- a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
@@ -517,8 +517,14 @@ void testToLocale_Locale_defaults() {
         assertEquals(Locale.getDefault(), 
LocaleUtils.toLocale(Locale.getDefault()));
     }
 
+    @ParameterizedTest
+    @MethodSource("java.util.Locale#getISOCountries")
+    void testToLocaleGetIso3Country(final String country) {
+        assertEquals(LocaleUtils.ofCountry(country).getISO3Country(), 
LocaleUtils.toLocale(country).getISO3Country());
+    }
+
     @Test
-    void testToLocaleGetIso3Country() {
+    void testToLocaleGetIso3CountryKnown() {
         assertEquals("USA", LocaleUtils.toLocale("US").getISO3Country());
         assertEquals("GBR", LocaleUtils.toLocale("GB").getISO3Country());
         assertEquals("PAK", LocaleUtils.toLocale("PK").getISO3Country());
@@ -528,7 +534,7 @@ void testToLocaleGetIso3Country() {
 
     @Test
     @DefaultLocale(country = "US", language = "en")
-    void testToLocaleGetIso3Language() {
+    void testToLocaleGetIso3LanguageKown() {
         assertEquals("United States", 
LocaleUtils.toLocale("US").getDisplayCountry());
         assertEquals("United Kingdom", 
LocaleUtils.toLocale("GB").getDisplayCountry());
         assertEquals("Pakistan", 
LocaleUtils.toLocale("PK").getDisplayCountry());
@@ -536,6 +542,12 @@ void testToLocaleGetIso3Language() {
         assertEquals("France", LocaleUtils.toLocale("FR").getDisplayCountry());
     }
 
+    @ParameterizedTest
+    @MethodSource("java.util.Locale#getISOCountries")
+    void testToLocaleGetIso3LanguageKown(final String country) {
+        assertEquals(LocaleUtils.ofCountry(country).getDisplayCountry(), 
LocaleUtils.toLocale(country).getDisplayCountry());
+    }
+
     /**
      * Test toLocale(Locale) method.
      */

Reply via email to