]> granicus.if.org Git - icu/commitdiff
ICU-20018 Remove hardcoded expectations on available locales.
authorFredrik Roubert <roubert@google.com>
Tue, 10 Jul 2018 21:00:43 +0000 (23:00 +0200)
committerFredrik Roubert <fredrik@roubert.name>
Mon, 6 Aug 2018 09:15:39 +0000 (11:15 +0200)
Both the number of installed locales and the name of the last locale
change with updates to and customizations of CLDR/ICU data so test
expectations on these values will cause bogus test failures.

icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java

index c0340ba0128a85356d2d3eb2625c3c77a5591d1c..3435d9894d66f678063183815f1465e1efe86b4f 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.regex.Pattern;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -1001,13 +1002,16 @@ public class ULocaleTest extends TestFmwk {
     }
 
     @Test
-    public void TestGetAvailable(){
+    public void TestGetAvailable() {
         ULocale[] locales = ULocale.getAvailableLocales();
-        if(locales.length<10){
-            errln("Did not get the correct result from getAvailableLocales");
+        if (locales.length < 1) {
+            errln("Did not get any results from getAvailableLocales");
         }
-        if(!locales[locales.length-1].getName().equals("zu_ZA")){
-            errln("Did not get the expected result");
+        final Pattern PATTERN = Pattern.compile("^\\p{Lower}{2,3}$");
+        for (ULocale locale : locales) {
+            if (!PATTERN.matcher(locale.getLanguage()).matches()) {
+                errln("Got impossible locale from getAvailableLocales: " + locale.getName());
+            }
         }
     }