From a36619060c382d759838417a6488f537ff964878 Mon Sep 17 00:00:00 2001 From: Mihai Nita Date: Thu, 9 Mar 2023 11:25:03 -0800 Subject: [PATCH] ICU-22279 Fix invalid new Locale in testing --- .../icu/dev/test/collator/CollationAPITest.java | 4 ++-- .../icu/dev/test/collator/CollationMiscTest.java | 2 +- .../ibm/icu/dev/test/calendar/JapaneseTest.java | 2 +- .../dev/test/format/CompactDecimalFormatTest.java | 2 +- .../dev/test/format/DateFormatRegressionTest.java | 2 +- .../ibm/icu/dev/test/format/DateFormatTest.java | 10 +++++----- .../dev/test/format/DateIntervalFormatTest.java | 14 +++++++------- .../com/ibm/icu/dev/test/format/TimeUnitTest.java | 6 +++--- .../icu/dev/test/serializable/FormatHandler.java | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationAPITest.java b/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationAPITest.java index 6e9b126d5844..662a353df53b 100644 --- a/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationAPITest.java +++ b/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationAPITest.java @@ -1582,7 +1582,7 @@ public boolean visible(){ */ try { TestCreateCollator tcc = new TestCreateCollator(); - tcc.createCollator(new Locale("en_US")); + tcc.createCollator(new Locale("en", "US")); } catch (Exception e) { errln("Collator.createCollator(Locale) was not suppose to " + "return an exception."); } @@ -1602,7 +1602,7 @@ public boolean visible(){ */ try { TestCreateCollator tcc = new TestCreateCollator(); - tcc.getDisplayName(new Locale("en_US"), new Locale("jp_JP")); + tcc.getDisplayName(new Locale("en", "US"), new Locale("jp", "JP")); } catch (Exception e) { errln("Collator.getDisplayName(Locale,Locale) was not suppose to return an exception."); } diff --git a/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java b/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java index 904a7d8be24d..be857bfb6572 100644 --- a/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java +++ b/icu4j/main/tests/collate/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java @@ -1263,7 +1263,7 @@ public void TestHangulTailoring() { // no such locale in icu4j // logln("Using ko__LOTUS locale\n"); - // genericLocaleStarter(new Locale("ko__LOTUS", ""), koreanData); + // genericLocaleStarter(new Locale("ko", "", "LOTUS"), koreanData); } @Test diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java index 1f98d383c3ab..c37a24276dee 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java @@ -285,7 +285,7 @@ public void Test5345parse() { SimpleDateFormat fmt = (SimpleDateFormat)c.getDateTimeFormat(1,1,new ULocale("en_US@calendar=japanese")); fmt.applyPattern("G y"); logln("fmt's locale = " + fmt.getLocale(ULocale.ACTUAL_LOCALE)); - //SimpleDateFormat fmt = new SimpleDateFormat("G y", new Locale("en_US@calendar=japanese")); + //SimpleDateFormat fmt = new SimpleDateFormat("G y", new ULocale("en_US@calendar=japanese")); long aDateLong = -3197117222000L; // 1868-09-08 00:00 Pacific Time (GMT-07:52:58) if (TimeZone.getDefaultTimeZoneType() == TimeZone.TIMEZONE_JDK) { // Java time zone implementation does not support LMTs diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java index a0c344dfaba2..f30d33504a90 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java @@ -399,7 +399,7 @@ public void TestEnglishShort() { @Test public void TestArabicLongStyle() { NumberFormat cdf = - CompactDecimalFormat.getInstance(new Locale("ar-EG"), CompactStyle.LONG); + CompactDecimalFormat.getInstance(new Locale("ar", "EG"), CompactStyle.LONG); assertEquals("Arabic Long", "\u061C-\u0665\u066B\u0663 \u0623\u0644\u0641", cdf.format(-5300)); } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatRegressionTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatRegressionTest.java index ade03a88eacd..6e760b998caa 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatRegressionTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatRegressionTest.java @@ -1273,7 +1273,7 @@ public void Test12902_yWithGregoCalInThaiLoc() { @Test public void TestT10110() { try { - SimpleDateFormat formatter = new SimpleDateFormat("Gy年M月d日E", new Locale("zh_Hans")); + SimpleDateFormat formatter = new SimpleDateFormat("Gy年M月d日E", Locale.forLanguageTag("zh-Hans")); /* Object parsed = */ formatter.parseObject("610000"); } catch(ParseException pe) { diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java index da0f83a882e2..c7f1daaf8c9a 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java @@ -2465,13 +2465,13 @@ public void TestCoverage() { sym.equals(null); sym = new ChineseDateFormatSymbols(); - sym = new ChineseDateFormatSymbols(new Locale("en_US")); + sym = new ChineseDateFormatSymbols(new Locale("en", "US")); try{ - sym = new ChineseDateFormatSymbols(null, new Locale("en_US")); + sym = new ChineseDateFormatSymbols(null, new Locale("en", "US")); errln("ChineseDateFormatSymbols(Calender, Locale) was suppose to return a null " + "pointer exception for a null paramater."); } catch(Exception e){} - sym = new ChineseDateFormatSymbols(new ChineseCalendar(), new Locale("en_US")); + sym = new ChineseDateFormatSymbols(new ChineseCalendar(), new Locale("en", "US")); try{ sym = new ChineseDateFormatSymbols(null, new ULocale("en_US")); errln("ChineseDateFormatSymbols(Calender, ULocale) was suppose to return a null " + @@ -4011,8 +4011,8 @@ public void TestGetPatternInstance(){ try{ @SuppressWarnings("unused") DateFormat df = DateFormat.getPatternInstance(""); - df = DateFormat.getPatternInstance("", new Locale("en_US")); - df = DateFormat.getPatternInstance(null, "", new Locale("en_US")); + df = DateFormat.getPatternInstance("", new Locale("en", "US")); + df = DateFormat.getPatternInstance(null, "", new Locale("en", "US")); } catch(Exception e) { errln("DateFormat.getPatternInstance is not suppose to return an exception, got: " + e.toString()); //e.printStackTrace(); diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java index b2218efd1892..0cda121a4226 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java @@ -2241,13 +2241,13 @@ public void testCreateInstanceForAllLocales() { public void testTicket20707() { TimeZone tz = TimeZone.getTimeZone("UTC"); Locale locales[] = { - new Locale("en-u-hc-h24"), - new Locale("en-u-hc-h23"), - new Locale("en-u-hc-h12"), - new Locale("en-u-hc-h11"), - new Locale("en"), - new Locale("en-u-hc-h25"), - new Locale("hi-IN-u-hc-h11") + Locale.forLanguageTag("en-u-hc-h24"), + Locale.forLanguageTag("en-u-hc-h23"), + Locale.forLanguageTag("en-u-hc-h12"), + Locale.forLanguageTag("en-u-hc-h11"), + Locale.forLanguageTag("en"), + Locale.forLanguageTag("en-u-hc-h25"), + Locale.forLanguageTag("hi-IN-u-hc-h11") }; // Clomuns: hh, HH, kk, KK, jj, JJs, CC diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeUnitTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeUnitTest.java index c65be9fbbe21..a55c57a438d3 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeUnitTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeUnitTest.java @@ -115,7 +115,7 @@ public void TestAPI() { format.setLocale(es); formatParsing(format); - format.setLocale(new Locale("pt_BR")); + format.setLocale(new Locale("pt", "BR")); formatParsing(format); format = new TimeUnitFormat(new Locale("de")); formatParsing(format); @@ -343,7 +343,7 @@ public void TestTimeUnitFormat() { } for (int i = 0; i < cases.length; i++) { try { - TimeUnitFormat tuf = new TimeUnitFormat(new Locale("en_US"), cases[i]); + TimeUnitFormat tuf = new TimeUnitFormat(new Locale("en", "US"), cases[i]); errln("TimeUnitFormat(ULocale,int) was suppose to return an " + "exception for a style value of " + cases[i] + "passed into the constructor."); } catch (Exception e) { @@ -358,7 +358,7 @@ public void TestTimeUnitFormat() { public void TestSetLocale() { // Tests when "if ( locale != this.locale )" is false TimeUnitFormat tuf = new TimeUnitFormat(new ULocale("en_US")); - if (!tuf.setLocale(new ULocale("en_US")).equals(tuf) && !tuf.setLocale(new Locale("en_US")).equals(tuf)) { + if (!tuf.setLocale(new ULocale("en_US")).equals(tuf) && !tuf.setLocale(new Locale("en", "US")).equals(tuf)) { errln("TimeUnitFormat.setLocale(ULocale) was suppose to " + "return the same TimeUnitFormat object if the same " + "ULocale is entered as a parameter."); } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/FormatHandler.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/FormatHandler.java index 72df5c946790..47b0980f7a45 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/FormatHandler.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/FormatHandler.java @@ -1743,7 +1743,7 @@ public Object[] getTestObjects() { CurrencyPluralInfo currencyPluralInfo[] = { new CurrencyPluralInfo(), new CurrencyPluralInfo(new ULocale("en_US")), - CurrencyPluralInfo.getInstance(), CurrencyPluralInfo.getInstance(new Locale("en_US")), + CurrencyPluralInfo.getInstance(), CurrencyPluralInfo.getInstance(new Locale("en", "US")), CurrencyPluralInfo.getInstance(new ULocale("en_US")) }; for(int i=0; i