8310818: Refactor more Locale tests to use JUnit

Reviewed-by: lancea, naoto
This commit is contained in:
Justin Lu 2023-07-07 19:12:13 +00:00
parent 5667afc362
commit 12e9430910
10 changed files with 518 additions and 523 deletions

@ -1,291 +0,0 @@
/*
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @summary test ISO639-2 language codes
* @library /java/text/testlib
* @compile -encoding ascii Bug4175998Test.java
* @run main Bug4175998Test
* @bug 4175998 8303917
*/
/*
*
*
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
*
* The original version of this source code and documentation is
* copyrighted and owned by IBM. These materials are provided
* under terms of a License Agreement between IBM and Sun.
* This technology is protected by multiple US and International
* patents. This notice and attribution to IBM may not be removed.
*
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.*;
/**
* Bug4175998Test verifies that the following bug has been fixed:
* Bug 4175998 - The java.util.Locale.getISO3Language() returns wrong result for a locale with
* language code 'ta'(Tamil).
*/
public class Bug4175998Test extends IntlTest {
public static void main(String[] args) throws Exception {
new Bug4175998Test().run(args);
//generateTables(); //uncomment this to regenerate data tables
}
public void testIt() throws Exception {
boolean bad = false;
for (final String[] localeCodes : CODES) {
final Locale l = Locale.of(localeCodes[0]);
final String iso3 = l.getISO3Language();
if (!iso3.equals(localeCodes[1])) {
logln("Locale(" + l + ") returned bad ISO3 language code."
+ " Got '" + iso3 + "' instead of '" + localeCodes[1] + "'");
bad = true;
}
}
if (bad) {
errln("Bad ISO3 language codes detected.");
}
}
private static final String[][] CODES = {
{"aa","aar","aar"},
{"ab","abk","abk"},
{"af","afr","afr"},
{"ak","aka","aka"},
{"sq","sqi","alb"},
{"am","amh","amh"},
{"ar","ara","ara"},
{"an","arg","arg"},
{"hy","hye","arm"},
{"as","asm","asm"},
{"av","ava","ava"},
{"ae","ave","ave"},
{"ay","aym","aym"},
{"az","aze","aze"},
{"ba","bak","bak"},
{"bm","bam","bam"},
{"eu","eus","baq"},
{"be","bel","bel"},
{"bn","ben","ben"},
{"bh","bih","bih"},
{"bi","bis","bis"},
{"bs","bos","bos"},
{"br","bre","bre"},
{"bg","bul","bul"},
{"my","mya","bur"},
{"ca","cat","cat"},
{"ch","cha","cha"},
{"ce","che","che"},
{"zh","zho","chi"},
{"cu","chu","chu"},
{"cv","chv","chv"},
{"kw","cor","cor"},
{"co","cos","cos"},
{"cr","cre","cre"},
{"cs","ces","cze"},
{"da","dan","dan"},
{"dv","div","div"},
{"nl","nld","dut"},
{"dz","dzo","dzo"},
{"en","eng","eng"},
{"eo","epo","epo"},
{"et","est","est"},
{"ee","ewe","ewe"},
{"fo","fao","fao"},
{"fj","fij","fij"},
{"fi","fin","fin"},
{"fr","fra","fre"},
{"fy","fry","fry"},
{"ff","ful","ful"},
{"ka","kat","geo"},
{"de","deu","ger"},
{"gd","gla","gla"},
{"ga","gle","gle"},
{"gl","glg","glg"},
{"gv","glv","glv"},
{"el","ell","gre"},
{"gn","grn","grn"},
{"gu","guj","guj"},
{"ht","hat","hat"},
{"ha","hau","hau"},
{"he","heb","heb"},
{"hz","her","her"},
{"hi","hin","hin"},
{"ho","hmo","hmo"},
{"hr","hrv","hrv"},
{"hu","hun","hun"},
{"ig","ibo","ibo"},
{"is","isl","ice"},
{"io","ido","ido"},
{"ii","iii","iii"},
{"iu","iku","iku"},
{"ie","ile","ile"},
{"ia","ina","ina"},
{"id","ind","ind"},
{"ik","ipk","ipk"},
{"it","ita","ita"},
{"jv","jav","jav"},
{"ja","jpn","jpn"},
{"kl","kal","kal"},
{"kn","kan","kan"},
{"ks","kas","kas"},
{"kr","kau","kau"},
{"kk","kaz","kaz"},
{"km","khm","khm"},
{"ki","kik","kik"},
{"rw","kin","kin"},
{"ky","kir","kir"},
{"kv","kom","kom"},
{"kg","kon","kon"},
{"ko","kor","kor"},
{"kj","kua","kua"},
{"ku","kur","kur"},
{"lo","lao","lao"},
{"la","lat","lat"},
{"lv","lav","lav"},
{"li","lim","lim"},
{"ln","lin","lin"},
{"lt","lit","lit"},
{"lb","ltz","ltz"},
{"lu","lub","lub"},
{"lg","lug","lug"},
{"mk","mkd","mac"},
{"mh","mah","mah"},
{"ml","mal","mal"},
{"mi","mri","mao"},
{"mr","mar","mar"},
{"ms","msa","may"},
{"mg","mlg","mlg"},
{"mt","mlt","mlt"},
{"mn","mon","mon"},
{"na","nau","nau"},
{"nv","nav","nav"},
{"nr","nbl","nbl"},
{"nd","nde","nde"},
{"ng","ndo","ndo"},
{"ne","nep","nep"},
{"nn","nno","nno"},
{"nb","nob","nob"},
{"no","nor","nor"},
{"ny","nya","nya"},
{"oc","oci","oci"},
{"oj","oji","oji"},
{"or","ori","ori"},
{"om","orm","orm"},
{"os","oss","oss"},
{"pa","pan","pan"},
{"fa","fas","per"},
{"pi","pli","pli"},
{"pl","pol","pol"},
{"pt","por","por"},
{"ps","pus","pus"},
{"qu","que","que"},
{"rm","roh","roh"},
{"ro","ron","rum"},
{"rn","run","run"},
{"ru","rus","rus"},
{"sg","sag","sag"},
{"sa","san","san"},
{"si","sin","sin"},
{"sk","slk","slo"},
{"sl","slv","slv"},
{"se","sme","sme"},
{"sm","smo","smo"},
{"sn","sna","sna"},
{"sd","snd","snd"},
{"so","som","som"},
{"st","sot","sot"},
{"es","spa","spa"},
{"sc","srd","srd"},
{"sr","srp","srp"},
{"ss","ssw","ssw"},
{"su","sun","sun"},
{"sw","swa","swa"},
{"sv","swe","swe"},
{"ty","tah","tah"},
{"ta","tam","tam"},
{"tt","tat","tat"},
{"te","tel","tel"},
{"tg","tgk","tgk"},
{"tl","tgl","tgl"},
{"th","tha","tha"},
{"bo","bod","tib"},
{"ti","tir","tir"},
{"to","ton","ton"},
{"tn","tsn","tsn"},
{"ts","tso","tso"},
{"tk","tuk","tuk"},
{"tr","tur","tur"},
{"tw","twi","twi"},
{"ug","uig","uig"},
{"uk","ukr","ukr"},
{"ur","urd","urd"},
{"uz","uzb","uzb"},
{"ve","ven","ven"},
{"vi","vie","vie"},
{"vo","vol","vol"},
{"cy","cym","wel"},
{"wa","wln","wln"},
{"wo","wol","wol"},
{"xh","xho","xho"},
{"yi","yid","yid"},
{"yo","yor","yor"},
{"za","zha","zha"},
{"zu","zul","zul"},
};
// The following code was used to generate the table above from the two ISO standards.
private static final String ISO639 = "ISO-639-2_utf-8.txt";
private static void generateTables() {
try {
BufferedReader ISO639File = new BufferedReader(new FileReader(ISO639));
for (String line = ISO639File.readLine(); line != null; line = ISO639File.readLine()) {
String[] tokens= line.split("\\|");
String iso639_1 = tokens[2];
String iso639_2B = tokens[1];
String iso639_2T = tokens[0];
if (iso639_1.isEmpty()){
continue; // Skip if not both a 639-1 and 639-2 code
}
if (iso639_2B.isEmpty()){
iso639_2B = iso639_2T; // Default 639/B to 639/T if empty
}
System.out.printf("""
{"%s","%s","%s"},
""", iso639_1, iso639_2B, iso639_2T);
}
} catch (Exception e) {
System.out.println(e);
}
}
}
// CODES generated from https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
// on March 9th, 2023.

@ -1,71 +0,0 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8025703
* @summary Verify implementation for Locale matching.
* @run main Bug8025703
*/
import java.util.*;
import java.util.Locale.LanguageRange;
public class Bug8025703 {
public static void main(String[] args) {
boolean err = false;
String[][] mappings = {{"ilw", "gal"},
{"meg", "cir"},
{"pcr", "adx"},
{"xia", "acn"},
{"yos", "zom"}};
for (int i = 0; i < mappings.length; i++) {
List<LanguageRange> got = LanguageRange.parse(mappings[i][0]);
ArrayList<LanguageRange> expected = new ArrayList<>();
expected.add(new LanguageRange(mappings[i][0], 1.0));
expected.add(new LanguageRange(mappings[i][1], 1.0));
if (!expected.equals(got)) {
err = true;
System.err.println("Incorrect language ranges. ");
for (LanguageRange lr : expected) {
System.err.println(" Expected: range="
+ lr.getRange() + ", weight=" + lr.getWeight());
}
for (LanguageRange lr : got) {
System.err.println(" Got: range="
+ lr.getRange() + ", weight=" + lr.getWeight());
}
}
}
if (err) {
throw new RuntimeException("Failed.");
}
}
}

@ -1,99 +0,0 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8032842 8175539
* @summary Checks that the filterTags() and lookup() methods
* preserve the case of matching language tag(s).
* Before 8032842 fix these methods return the matching
* language tag(s) in lowercase.
* Also, checks the filterTags() to return only unique
* (ignoring case considerations) matching tags.
*
*/
import java.util.List;
import java.util.Locale;
import java.util.Locale.FilteringMode;
import java.util.Locale.LanguageRange;
public class Bug8032842 {
public static void main(String[] args) {
// test filterBasic() for preserving the case of matching tags for
// the language range '*', with no duplicates in the matching tags
testFilter("*", List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP",
"JA-JP", "en-GB"),
List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP", "JA-JP"),
FilteringMode.AUTOSELECT_FILTERING);
// test filterBasic() for preserving the case of matching tags for
// basic ranges other than *, with no duplicates in the matching tags
testFilter("mtm-RU, en-GB", List.of("En-Gb", "mTm-RU", "en-US",
"en-latn", "en-GB"),
List.of("mTm-RU", "En-Gb"), FilteringMode.AUTOSELECT_FILTERING);
// test filterExtended() for preserving the case of matching tags for
// the language range '*', with no duplicates in the matching tags
testFilter("*", List.of("de-CH", "hi-in", "En-GB", "hi-IN",
"ja-Latn-JP", "JA-JP"),
List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP", "JA-JP"),
FilteringMode.EXTENDED_FILTERING);
// test filterExtended() for preserving the case of matching tags for
// extended ranges other than *, with no duplicates in the matching tags
testFilter("*-ch;q=0.5, *-Latn;q=0.4", List.of("fr-CH", "de-Ch",
"en-latn", "en-US", "en-Latn"),
List.of("fr-CH", "de-Ch", "en-latn"),
FilteringMode.EXTENDED_FILTERING);
// test lookupTag() for preserving the case of matching tag
testLookup("*-ch;q=0.5", List.of("en", "fR-cH"), "fR-cH");
}
public static void testFilter(String ranges, List<String> tags,
List<String> expected, FilteringMode mode) {
List<LanguageRange> priorityList = LanguageRange.parse(ranges);
List<String> actual = Locale.filterTags(priorityList, tags, mode);
if (!actual.equals(expected)) {
throw new RuntimeException("[filterTags() failed for the language"
+ " range: " + ranges + ", Expected: " + expected
+ ", Found: " + actual + "]");
}
}
public static void testLookup(String ranges, List<String> tags,
String expected) {
List<LanguageRange> priorityList = LanguageRange.parse(ranges);
String actual = Locale.lookupTag(priorityList, tags);
if (!actual.equals(expected)) {
throw new RuntimeException("[lookupTag() failed for the language"
+ " range: " + ranges + ", Expected: " + expected
+ ", Found: " + actual + "]");
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,27 +25,36 @@
* @test
* @bug 8008577 8138613
* @summary Check whether CLDR locale provider adapter is enabled by default
* @compile -XDignore.symbol.file Bug8008577.java
* @compile -XDignore.symbol.file ExpectedAdapterTypes.java
* @modules java.base/sun.util.locale.provider
* @run main Bug8008577
* @run junit ExpectedAdapterTypes
*/
import java.util.Arrays;
import java.util.List;
import sun.util.locale.provider.LocaleProviderAdapter;
public class Bug8008577 {
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ExpectedAdapterTypes {
static final LocaleProviderAdapter.Type[] expected = {
LocaleProviderAdapter.Type.CLDR,
LocaleProviderAdapter.Type.JRE,
};
public static void main(String[] args) {
List<LocaleProviderAdapter.Type> types = LocaleProviderAdapter.getAdapterPreference();
List<LocaleProviderAdapter.Type> expectedList = Arrays.asList(expected);
if (!types.equals(expectedList)) {
throw new RuntimeException("Default locale provider adapter list is incorrect");
}
/**
* This test ensures LocaleProviderAdapter.getAdapterPreference() returns
* the correct preferred adapter types. This test should fail whenever a change is made
* to the implementation and the expected list is not updated accordingly.
*/
@Test
public void correctAdapterListTest() {
List<LocaleProviderAdapter.Type> actualTypes = LocaleProviderAdapter.getAdapterPreference();
List<LocaleProviderAdapter.Type> expectedTypes = Arrays.asList(expected);
assertEquals(actualTypes, expectedTypes, String.format("getAdapterPreference() " +
"returns: %s, but the expected adapter list returns: %s", actualTypes, expectedTypes));
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,7 +27,9 @@
* @summary Test obsolete ISO3166-1 alpha-2 country codes should not be retrieved.
* ISO3166-1 alpha-2, ISO3166-1 alpha-3, ISO3166-3 country codes
* from overloaded getISOCountries(Iso3166 type) are retrieved correctly.
* @run junit ISO3166
*/
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@ -35,7 +37,9 @@ import java.util.Locale.IsoCountryCode;
import java.util.Set;
import java.util.stream.Collectors;
public class Bug8071929 {
import org.junit.jupiter.api.Test;
public class ISO3166 {
private static final List<String> ISO3166_1_ALPHA2_OBSOLETE_CODES = List.of("AN", "BU", "CS",
"NT", "SF", "TP", "YU", "ZR");
@ -78,7 +82,8 @@ public class Bug8071929 {
* This method checks that obsolete ISO3166-1 alpha-2 country codes are not
* retrieved in output of getISOCountries() method.
*/
private static void checkISO3166_1_Alpha2ObsoleteCodes() {
@Test
public void checkISO3166_1_Alpha2ObsoleteCodes() {
Set<String> unexpectedCodes = ISO3166_1_ALPHA2_OBSOLETE_CODES.stream().
filter(Set.of(Locale.getISOCountries())::contains).collect(Collectors.toSet());
if (!unexpectedCodes.isEmpty()) {
@ -91,7 +96,8 @@ public class Bug8071929 {
* This method checks that ISO3166-3 country codes which are PART3 of
* IsoCountryCode enum, are retrieved correctly.
*/
private static void checkISO3166_3Codes() {
@Test
public void checkISO3166_3Codes() {
Set<String> iso3166_3Codes = Locale.getISOCountries(IsoCountryCode.PART3);
if (!iso3166_3Codes.equals(ISO3166_3EXPECTED)) {
reportDifference(iso3166_3Codes, ISO3166_3EXPECTED);
@ -102,7 +108,8 @@ public class Bug8071929 {
* This method checks that ISO3166-1 alpha-3 country codes which are
* PART1_ALPHA3 of IsoCountryCode enum, are retrieved correctly.
*/
private static void checkISO3166_1_Alpha3Codes() {
@Test
public void checkISO3166_1_Alpha3Codes() {
Set<String> iso3166_1_Alpha3Codes = Locale.getISOCountries(IsoCountryCode.PART1_ALPHA3);
if (!iso3166_1_Alpha3Codes.equals(ISO3166_1_ALPHA3_EXPECTED)) {
reportDifference(iso3166_1_Alpha3Codes, ISO3166_1_ALPHA3_EXPECTED);
@ -113,7 +120,8 @@ public class Bug8071929 {
* This method checks that ISO3166-1 alpha-2 country codes, which are
* PART1_ALPHA2 of IsoCountryCode enum, are retrieved correctly.
*/
private static void checkISO3166_1_Alpha2Codes() {
@Test
public void checkISO3166_1_Alpha2Codes() {
Set<String> iso3166_1_Alpha2Codes = Locale.getISOCountries(IsoCountryCode.PART1_ALPHA2);
Set<String> ISO3166_1_ALPHA2_EXPECTED = Set.of(Locale.getISOCountries());
if (!iso3166_1_Alpha2Codes.equals(ISO3166_1_ALPHA2_EXPECTED)) {
@ -139,11 +147,4 @@ public class Bug8071929 {
+ expectedSet);
}
}
public static void main(String[] args) {
checkISO3166_1_Alpha2ObsoleteCodes();
checkISO3166_1_Alpha2Codes();
checkISO3166_1_Alpha3Codes();
checkISO3166_3Codes();
}
}

@ -0,0 +1,297 @@
/*
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @summary test ISO639-2 language codes
* @library /java/text/testlib
* @compile -encoding ascii ISO639.java
* @bug 4175998 8303917
* @run junit ISO639
*/
/*
*
*
* (C) Copyright IBM Corp. 1998 - All Rights Reserved
*
* The original version of this source code and documentation is
* copyrighted and owned by IBM. These materials are provided
* under terms of a License Agreement between IBM and Sun.
* This technology is protected by multiple US and International
* patents. This notice and attribution to IBM may not be removed.
*
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Locale;
import java.util.stream.Stream;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ISO639 {
/**
* This test verifies for a given locale created from the ISO639 2-letter code,
* the correct ISO639 3-letter code is returned when calling getISO3Language().
*/
@ParameterizedTest
@MethodSource("expectedISO639Codes")
public void ISO3LetterTest(String ISO2, String expectedISO3) {
Locale loc = Locale.of(ISO2);
String actualISO3 = loc.getISO3Language();
assertEquals(actualISO3, expectedISO3,
String.format("The Locale '%s' returned a bad ISO3 language code. " +
"Got '%s' instead of '%s'", loc, actualISO3, expectedISO3));
}
// expectedISO639Codes generated from https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
// on March 9th, 2023.
private static Stream<Arguments> expectedISO639Codes() {
return Stream.of(
Arguments.of("aa","aar","aar"),
Arguments.of("ab","abk","abk"),
Arguments.of("af","afr","afr"),
Arguments.of("ak","aka","aka"),
Arguments.of("sq","sqi","alb"),
Arguments.of("am","amh","amh"),
Arguments.of("ar","ara","ara"),
Arguments.of("an","arg","arg"),
Arguments.of("hy","hye","arm"),
Arguments.of("as","asm","asm"),
Arguments.of("av","ava","ava"),
Arguments.of("ae","ave","ave"),
Arguments.of("ay","aym","aym"),
Arguments.of("az","aze","aze"),
Arguments.of("ba","bak","bak"),
Arguments.of("bm","bam","bam"),
Arguments.of("eu","eus","baq"),
Arguments.of("be","bel","bel"),
Arguments.of("bn","ben","ben"),
Arguments.of("bh","bih","bih"),
Arguments.of("bi","bis","bis"),
Arguments.of("bs","bos","bos"),
Arguments.of("br","bre","bre"),
Arguments.of("bg","bul","bul"),
Arguments.of("my","mya","bur"),
Arguments.of("ca","cat","cat"),
Arguments.of("ch","cha","cha"),
Arguments.of("ce","che","che"),
Arguments.of("zh","zho","chi"),
Arguments.of("cu","chu","chu"),
Arguments.of("cv","chv","chv"),
Arguments.of("kw","cor","cor"),
Arguments.of("co","cos","cos"),
Arguments.of("cr","cre","cre"),
Arguments.of("cs","ces","cze"),
Arguments.of("da","dan","dan"),
Arguments.of("dv","div","div"),
Arguments.of("nl","nld","dut"),
Arguments.of("dz","dzo","dzo"),
Arguments.of("en","eng","eng"),
Arguments.of("eo","epo","epo"),
Arguments.of("et","est","est"),
Arguments.of("ee","ewe","ewe"),
Arguments.of("fo","fao","fao"),
Arguments.of("fj","fij","fij"),
Arguments.of("fi","fin","fin"),
Arguments.of("fr","fra","fre"),
Arguments.of("fy","fry","fry"),
Arguments.of("ff","ful","ful"),
Arguments.of("ka","kat","geo"),
Arguments.of("de","deu","ger"),
Arguments.of("gd","gla","gla"),
Arguments.of("ga","gle","gle"),
Arguments.of("gl","glg","glg"),
Arguments.of("gv","glv","glv"),
Arguments.of("el","ell","gre"),
Arguments.of("gn","grn","grn"),
Arguments.of("gu","guj","guj"),
Arguments.of("ht","hat","hat"),
Arguments.of("ha","hau","hau"),
Arguments.of("he","heb","heb"),
Arguments.of("hz","her","her"),
Arguments.of("hi","hin","hin"),
Arguments.of("ho","hmo","hmo"),
Arguments.of("hr","hrv","hrv"),
Arguments.of("hu","hun","hun"),
Arguments.of("ig","ibo","ibo"),
Arguments.of("is","isl","ice"),
Arguments.of("io","ido","ido"),
Arguments.of("ii","iii","iii"),
Arguments.of("iu","iku","iku"),
Arguments.of("ie","ile","ile"),
Arguments.of("ia","ina","ina"),
Arguments.of("id","ind","ind"),
Arguments.of("ik","ipk","ipk"),
Arguments.of("it","ita","ita"),
Arguments.of("jv","jav","jav"),
Arguments.of("ja","jpn","jpn"),
Arguments.of("kl","kal","kal"),
Arguments.of("kn","kan","kan"),
Arguments.of("ks","kas","kas"),
Arguments.of("kr","kau","kau"),
Arguments.of("kk","kaz","kaz"),
Arguments.of("km","khm","khm"),
Arguments.of("ki","kik","kik"),
Arguments.of("rw","kin","kin"),
Arguments.of("ky","kir","kir"),
Arguments.of("kv","kom","kom"),
Arguments.of("kg","kon","kon"),
Arguments.of("ko","kor","kor"),
Arguments.of("kj","kua","kua"),
Arguments.of("ku","kur","kur"),
Arguments.of("lo","lao","lao"),
Arguments.of("la","lat","lat"),
Arguments.of("lv","lav","lav"),
Arguments.of("li","lim","lim"),
Arguments.of("ln","lin","lin"),
Arguments.of("lt","lit","lit"),
Arguments.of("lb","ltz","ltz"),
Arguments.of("lu","lub","lub"),
Arguments.of("lg","lug","lug"),
Arguments.of("mk","mkd","mac"),
Arguments.of("mh","mah","mah"),
Arguments.of("ml","mal","mal"),
Arguments.of("mi","mri","mao"),
Arguments.of("mr","mar","mar"),
Arguments.of("ms","msa","may"),
Arguments.of("mg","mlg","mlg"),
Arguments.of("mt","mlt","mlt"),
Arguments.of("mn","mon","mon"),
Arguments.of("na","nau","nau"),
Arguments.of("nv","nav","nav"),
Arguments.of("nr","nbl","nbl"),
Arguments.of("nd","nde","nde"),
Arguments.of("ng","ndo","ndo"),
Arguments.of("ne","nep","nep"),
Arguments.of("nn","nno","nno"),
Arguments.of("nb","nob","nob"),
Arguments.of("no","nor","nor"),
Arguments.of("ny","nya","nya"),
Arguments.of("oc","oci","oci"),
Arguments.of("oj","oji","oji"),
Arguments.of("or","ori","ori"),
Arguments.of("om","orm","orm"),
Arguments.of("os","oss","oss"),
Arguments.of("pa","pan","pan"),
Arguments.of("fa","fas","per"),
Arguments.of("pi","pli","pli"),
Arguments.of("pl","pol","pol"),
Arguments.of("pt","por","por"),
Arguments.of("ps","pus","pus"),
Arguments.of("qu","que","que"),
Arguments.of("rm","roh","roh"),
Arguments.of("ro","ron","rum"),
Arguments.of("rn","run","run"),
Arguments.of("ru","rus","rus"),
Arguments.of("sg","sag","sag"),
Arguments.of("sa","san","san"),
Arguments.of("si","sin","sin"),
Arguments.of("sk","slk","slo"),
Arguments.of("sl","slv","slv"),
Arguments.of("se","sme","sme"),
Arguments.of("sm","smo","smo"),
Arguments.of("sn","sna","sna"),
Arguments.of("sd","snd","snd"),
Arguments.of("so","som","som"),
Arguments.of("st","sot","sot"),
Arguments.of("es","spa","spa"),
Arguments.of("sc","srd","srd"),
Arguments.of("sr","srp","srp"),
Arguments.of("ss","ssw","ssw"),
Arguments.of("su","sun","sun"),
Arguments.of("sw","swa","swa"),
Arguments.of("sv","swe","swe"),
Arguments.of("ty","tah","tah"),
Arguments.of("ta","tam","tam"),
Arguments.of("tt","tat","tat"),
Arguments.of("te","tel","tel"),
Arguments.of("tg","tgk","tgk"),
Arguments.of("tl","tgl","tgl"),
Arguments.of("th","tha","tha"),
Arguments.of("bo","bod","tib"),
Arguments.of("ti","tir","tir"),
Arguments.of("to","ton","ton"),
Arguments.of("tn","tsn","tsn"),
Arguments.of("ts","tso","tso"),
Arguments.of("tk","tuk","tuk"),
Arguments.of("tr","tur","tur"),
Arguments.of("tw","twi","twi"),
Arguments.of("ug","uig","uig"),
Arguments.of("uk","ukr","ukr"),
Arguments.of("ur","urd","urd"),
Arguments.of("uz","uzb","uzb"),
Arguments.of("ve","ven","ven"),
Arguments.of("vi","vie","vie"),
Arguments.of("vo","vol","vol"),
Arguments.of("cy","cym","wel"),
Arguments.of("wa","wln","wln"),
Arguments.of("wo","wol","wol"),
Arguments.of("xh","xho","xho"),
Arguments.of("yi","yid","yid"),
Arguments.of("yo","yor","yor"),
Arguments.of("za","zha","zha"),
Arguments.of("zu","zul","zul")
);
}
@Test
@Disabled("For updating expected ISO data, NOT an actual test")
public void getISOData() {
// Remove @Disabled to generate new ISO Data
generateTables();
}
private static final String ISO639 = "ISO-639-2_utf-8.txt";
private static void generateTables() {
try {
BufferedReader ISO639File = new BufferedReader(new FileReader(ISO639));
for (String line = ISO639File.readLine(); line != null; line = ISO639File.readLine()) {
String[] tokens= line.split("\\|");
String iso639_1 = tokens[2];
String iso639_2B = tokens[1];
String iso639_2T = tokens[0];
if (iso639_1.isEmpty()){
continue; // Skip if not both a 639-1 and 639-2 code
}
if (iso639_2B.isEmpty()){
iso639_2B = iso639_2T; // Default 639/B to 639/T if empty
}
System.out.printf("""
Arguments.of("%s","%s","%s"),
""", iso639_1, iso639_2B, iso639_2T);
}
} catch (Exception e) {
System.out.println(e);
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,9 +25,9 @@
* @test
* @bug 8001562
* @summary Verify that getAvailableLocales() in locale sensitive services
* classes return compatible set of locales as in JDK7.
* classes return compatible set of locales as in JDK7.
* @modules jdk.localedata
* @run main Bug8001562
* @run junit JDK7LocaleServiceDiffs
*/
import java.text.BreakIterator;
@ -40,8 +40,13 @@ import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Bug8001562 {
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
public class JDK7LocaleServiceDiffs {
static final List<String> jdk7availTags = List.of(
"ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW",
@ -72,27 +77,16 @@ public class Bug8001562 {
.collect(Collectors.toList());
}
public static void main(String[] args) {
List<Locale> avail = Arrays.asList(BreakIterator.getAvailableLocales());
diffLocale(BreakIterator.class, avail);
avail = Arrays.asList(Collator.getAvailableLocales());
diffLocale(Collator.class, avail);
avail = Arrays.asList(DateFormat.getAvailableLocales());
diffLocale(DateFormat.class, avail);
avail = Arrays.asList(DateFormatSymbols.getAvailableLocales());
diffLocale(DateFormatSymbols.class, avail);
avail = Arrays.asList(DecimalFormatSymbols.getAvailableLocales());
diffLocale(DecimalFormatSymbols.class, avail);
avail = Arrays.asList(NumberFormat.getAvailableLocales());
diffLocale(NumberFormat.class, avail);
avail = Arrays.asList(Locale.getAvailableLocales());
diffLocale(Locale.class, avail);
/**
* This test compares the locales returned by getAvailableLocales() from a
* locale sensitive service to the available JDK7 locales. If the locales from
* a locale sensitive service are found to not contain a JDK7 available tag,
* the test will fail.
*/
@ParameterizedTest
@MethodSource("serviceProvider")
public void compatibleLocalesTest(Class<?> c, List<Locale> locs) {
diffLocale(c, locs);
}
static void diffLocale(Class<?> c, List<Locale> locs) {
@ -119,4 +113,16 @@ public class Bug8001562 {
throw new RuntimeException("Above locale(s) were not included in the target available locales");
}
}
private static Stream<Arguments> serviceProvider() {
return Stream.of(
Arguments.of(BreakIterator.class, Arrays.asList(BreakIterator.getAvailableLocales())),
Arguments.of(Collator.class, Arrays.asList(Collator.getAvailableLocales())),
Arguments.of(DateFormat.class, Arrays.asList(DateFormat.getAvailableLocales())),
Arguments.of(DateFormatSymbols.class, Arrays.asList(DateFormatSymbols.getAvailableLocales())),
Arguments.of(DecimalFormatSymbols.class, Arrays.asList(DecimalFormatSymbols.getAvailableLocales())),
Arguments.of(NumberFormat.class, Arrays.asList(NumberFormat.getAvailableLocales())),
Arguments.of(Locale.class, Arrays.asList(Locale.getAvailableLocales()))
);
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,21 +25,40 @@
* @test
* @bug 8026766
* @summary Confirm that LanguageRange.toString() returns an expected result.
* @run main Bug8026766
* @run junit LRToString
*/
import java.util.Locale.LanguageRange;
import java.util.stream.Stream;
public class Bug8026766 {
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
public static void main(String[] args) {
LanguageRange lr1 = new LanguageRange("ja", 1.0);
LanguageRange lr2 = new LanguageRange("fr", 0.0);
import static org.junit.jupiter.api.Assertions.assertEquals;
if (!lr1.toString().equals("ja") ||
!lr2.toString().equals("fr;q=0.0")) {
throw new RuntimeException("LanguageRange.toString() returned an unexpected result.");
}
public class LRToString {
/**
* This test ensures that the output of LanguageRange.toString()
* returns an expected result, that is, the weight is hidden if it is
* equal to 1.0.
*/
@ParameterizedTest
@MethodSource("ranges")
public void toStringTest(String range, double weight) {
LanguageRange lr = new LanguageRange(range, weight);
String expected = weight == 1.0
? range
: range+";q="+weight;
assertEquals(lr.toString(), expected);
}
private static Stream<Arguments> ranges() {
return Stream.of(
Arguments.of("ja", 1.0),
Arguments.of("de", 0.5),
Arguments.of("fr", 0.0)
);
}
}

@ -23,7 +23,7 @@
/*
* @test
* @bug 8040211 8191404 8203872 8222980 8225435 8241082 8242010 8247432
* @bug 8025703 8040211 8191404 8203872 8222980 8225435 8241082 8242010 8247432
* 8258795 8267038 8287180 8302512 8304761 8306031 8308021
* @summary Checks the IANA language subtag registry data update
* (LSR Revision: 2023-05-11) with Locale and Locale.LanguageRange
@ -45,9 +45,9 @@ public class LanguageSubtagRegistryTest {
private static final String ACCEPT_LANGUAGE =
"Accept-Language: aam, adp, aeb, ajs, aog, apc, ajp, aue, bcg, bic, bpp, cey, cbr, cnp, cqu, crr, csp, csx, dif, dmw, dsz, ehs, ema,"
+ " en-gb-oed, gti, iba, jks, kdz, kjh, kmb, koj, kru, ksp, kwq, kxe, kzk, lgs, lii, lmm, lsb, lsc, lsn, lsv, lsw, lvi, mtm,"
+ " ngv, nns, ola, oyb, pat, phr, plu, pnd, pub, rib, rnb, rsn, scv, snz, sqx, suj, szy, taj, tdg, tjj, tjp, tpn, tvx,"
+ " umi, uss, uth, ysm, zko, wkr;q=0.9, ar-hyw;q=0.8, yug;q=0.5, gfx;q=0.4";
+ " en-gb-oed, gti, iba, ilw, jks, kdz, kjh, kmb, koj, kru, ksp, kwq, kxe, kzk, lgs, lii, lmm, lsb, lsc, lsn, lsv, lsw, lvi, meg, mtm,"
+ " ngv, nns, ola, oyb, pat, pcr, phr, plu, pnd, pub, rib, rnb, rsn, scv, snz, sqx, suj, szy, taj, tdg, tjj, tjp, tpn, tvx,"
+ " umi, uss, uth, xia, yos, ysm, zko, wkr;q=0.9, ar-hyw;q=0.8, yug;q=0.5, gfx;q=0.4";
private static final List<LanguageRange> EXPECTED_RANGE_LIST = List.of(
new LanguageRange("aam", 1.0),
new LanguageRange("aas", 1.0),
@ -102,6 +102,8 @@ public class LanguageSubtagRegistryTest {
new LanguageRange("iba", 1.0),
new LanguageRange("snb", 1.0),
new LanguageRange("blg", 1.0),
new LanguageRange("ilw", 1.0),
new LanguageRange("gal", 1.0),
new LanguageRange("jks", 1.0),
new LanguageRange("sgn-jks", 1.0),
new LanguageRange("kdz", 1.0),
@ -140,6 +142,8 @@ public class LanguageSubtagRegistryTest {
new LanguageRange("lsw", 1.0),
new LanguageRange("sgn-lsw", 1.0),
new LanguageRange("lvi", 1.0),
new LanguageRange("meg", 1.0),
new LanguageRange("cir", 1.0),
new LanguageRange("mtm", 1.0),
new LanguageRange("ymt", 1.0),
new LanguageRange("ngv", 1.0),
@ -154,6 +158,8 @@ public class LanguageSubtagRegistryTest {
new LanguageRange("jeg", 1.0),
new LanguageRange("pat", 1.0),
new LanguageRange("kxr", 1.0),
new LanguageRange("pcr", 1.0),
new LanguageRange("adx", 1.0),
new LanguageRange("phr", 1.0),
new LanguageRange("pmu", 1.0),
new LanguageRange("plu", 1.0),
@ -188,6 +194,10 @@ public class LanguageSubtagRegistryTest {
new LanguageRange("szd", 1.0),
new LanguageRange("uss", 1.0),
new LanguageRange("uth", 1.0),
new LanguageRange("xia", 1.0),
new LanguageRange("acn", 1.0),
new LanguageRange("yos", 1.0),
new LanguageRange("zom", 1.0),
new LanguageRange("ysm", 1.0),
new LanguageRange("sgn-ysm", 1.0),
new LanguageRange("zko", 1.0),

@ -0,0 +1,114 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8032842 8175539
* @summary Checks that the filterTags() and lookup() methods
* preserve the case of matching language tag(s).
* Before 8032842 fix these methods return the matching
* language tag(s) in lowercase.
* Also, checks the filterTags() to return only unique
* (ignoring case considerations) matching tags.
* @run junit PreserveTagCase
*/
import java.util.List;
import java.util.Locale;
import java.util.Locale.FilteringMode;
import java.util.Locale.LanguageRange;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PreserveTagCase {
/**
* This test ensures that Locale.filterTags() preserves the case of matching
* language tag(s).
*/
@ParameterizedTest
@MethodSource("filterProvider")
public static void testFilterTags(String ranges, List<String> tags,
List<String> expected, FilteringMode mode) {
List<LanguageRange> priorityList = LanguageRange.parse(ranges);
List<String> actual = Locale.filterTags(priorityList, tags, mode);
assertEquals(actual, expected, String.format("[filterTags() failed for " +
"the language range: %s, Expected: %s, Found: %s]", ranges, expected, actual));
}
/**
* This test ensures that Locale.lookupTag() preserves the case of matching
* language tag(s).
*/
@ParameterizedTest
@MethodSource("lookupProvider")
public static void testLookupTag(String ranges, List<String> tags,
String expected) {
List<LanguageRange> priorityList = LanguageRange.parse(ranges);
String actual = Locale.lookupTag(priorityList, tags);
assertEquals(actual, expected, String.format("[lookupTags() failed for " +
"the language range: %s, Expected: %s, Found: %s]", ranges, expected, actual));
}
private static Stream<Arguments> filterProvider() {
return Stream.of(
// test filterBasic() for preserving the case of matching tags for
// the language range '*', with no duplicates in the matching tags
Arguments.of("*",
List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP", "JA-JP", "en-GB"),
List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP", "JA-JP"),
FilteringMode.AUTOSELECT_FILTERING),
// test filterBasic() for preserving the case of matching tags for
// basic ranges other than *, with no duplicates in the matching tags
Arguments.of("mtm-RU, en-GB",
List.of("En-Gb", "mTm-RU", "en-US", "en-latn", "en-GB"),
List.of("mTm-RU", "En-Gb"),
FilteringMode.AUTOSELECT_FILTERING),
// test filterExtended() for preserving the case of matching tags for
// the language range '*', with no duplicates in the matching tags
Arguments.of("*",
List.of("de-CH", "hi-in", "En-GB", "hi-IN", "ja-Latn-JP", "JA-JP"),
List.of("de-CH", "hi-in", "En-GB", "ja-Latn-JP", "JA-JP"),
FilteringMode.EXTENDED_FILTERING),
// test filterExtended() for preserving the case of matching tags for
// extended ranges other than *, with no duplicates in the matching tags
Arguments.of("*-ch;q=0.5, *-Latn;q=0.4",
List.of("fr-CH", "de-Ch", "en-latn", "en-US", "en-Latn"),
List.of("fr-CH", "de-Ch", "en-latn"),
FilteringMode.EXTENDED_FILTERING)
);
}
private static Stream<Arguments> lookupProvider() {
return Stream.of(
// test lookupTag() for preserving the case of matching tag
Arguments.of("*-ch;q=0.5", List.of("en", "fR-cH"), "fR-cH"),
Arguments.of("*-Latn;q=0.4", List.of("en", "fR-LATn"), "fR-LATn")
);
}
}