Path: blob/master/test/jdk/java/util/Locale/Bug8001562.java
41149 views
/*1* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 800156226* @summary Verify that getAvailableLocales() in locale sensitive services27* classes return compatible set of locales as in JDK7.28* @modules jdk.localedata29* @run main Bug800156230*/3132import java.text.BreakIterator;33import java.text.Collator;34import java.text.DateFormat;35import java.text.DateFormatSymbols;36import java.text.DecimalFormatSymbols;37import java.text.NumberFormat;38import java.util.Arrays;39import java.util.List;40import java.util.Locale;41import java.util.stream.Collectors;4243public class Bug8001562 {4445static final List<String> jdk7availTags = List.of(46"ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW",47"ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SD", "ar-SY",48"ar-TN", "ar-YE", "be", "be-BY", "bg", "bg-BG", "ca", "ca-ES", "cs",49"cs-CZ", "da", "da-DK", "de", "de-AT", "de-CH", "de-DE", "de-LU", "el",50"el-CY", "el-GR", "en", "en-AU", "en-CA", "en-GB", "en-IE", "en-IN",51"en-MT", "en-NZ", "en-PH", "en-SG", "en-US", "en-ZA", "es", "es-AR",52"es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-ES", "es-GT",53"es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV",54"es-US", "es-UY", "es-VE", "et", "et-EE", "fi", "fi-FI", "fr", "fr-BE",55"fr-CA", "fr-CH", "fr-FR", "fr-LU", "ga", "ga-IE", "he", "he-IL",56"hi-IN", "hr", "hr-HR", "hu", "hu-HU", "id", "id-ID", "is", "is-IS",57"it", "it-CH", "it-IT", "ja", "ja-JP",58"ja-JP-u-ca-japanese-x-lvariant-JP", "ko", "ko-KR", "lt", "lt-LT", "lv",59"lv-LV", "mk", "mk-MK", "ms", "ms-MY", "mt", "mt-MT", "nl", "nl-BE",60"nl-NL", "no", "no-NO", "no-NO-x-lvariant-NY", "pl", "pl-PL", "pt",61"pt-BR", "pt-PT", "ro", "ro-RO", "ru", "ru-RU", "sk", "sk-SK", "sl",62"sl-SI", "sq", "sq-AL", "sr", "sr-BA", "sr-CS", "sr-Latn", "sr-Latn-BA",63"sr-Latn-ME", "sr-Latn-RS", "sr-ME", "sr-RS", "sv", "sv-SE", "th",64"th-TH", "th-TH-u-nu-thai-x-lvariant-TH", "tr", "tr-TR", "uk", "uk-UA",65"vi", "vi-VN", "zh", "zh-CN", "zh-HK", "zh-SG", "zh-TW");66static List<Locale> jdk7availLocs;6768static {69jdk7availLocs = jdk7availTags.stream()70.map(Locale::forLanguageTag)71.collect(Collectors.toList());72}7374public static void main(String[] args) {75List<Locale> avail = Arrays.asList(BreakIterator.getAvailableLocales());76diffLocale(BreakIterator.class, avail);7778avail = Arrays.asList(Collator.getAvailableLocales());79diffLocale(Collator.class, avail);8081avail = Arrays.asList(DateFormat.getAvailableLocales());82diffLocale(DateFormat.class, avail);8384avail = Arrays.asList(DateFormatSymbols.getAvailableLocales());85diffLocale(DateFormatSymbols.class, avail);8687avail = Arrays.asList(DecimalFormatSymbols.getAvailableLocales());88diffLocale(DecimalFormatSymbols.class, avail);8990avail = Arrays.asList(NumberFormat.getAvailableLocales());91diffLocale(NumberFormat.class, avail);9293avail = Arrays.asList(Locale.getAvailableLocales());94diffLocale(Locale.class, avail);95}9697static void diffLocale(Class<?> c, List<Locale> locs) {98String diff = "";99100System.out.printf("Only in target locales (%s.getAvailableLocales()): ", c.getSimpleName());101for (Locale l : locs) {102if (!jdk7availLocs.contains(l)) {103diff += "\"" + l.toLanguageTag() + "\", ";104}105}106System.out.println(diff);107diff = "";108109System.out.printf("Only in JDK7 (%s.getAvailableLocales()): ", c.getSimpleName());110for (Locale l : jdk7availLocs) {111if (!locs.contains(l)) {112diff += "\"" + l.toLanguageTag() + "\", ";113}114}115System.out.println(diff);116117if (diff.length() > 0) {118throw new RuntimeException("Above locale(s) were not included in the target available locales");119}120}121}122123124