Path: blob/master/test/jdk/java/util/Locale/Bug8179071.java
41149 views
/*1* Copyright (c) 2018, 2020, 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 8179071 8202537 8231273 825131726* @summary Test that language aliases of CLDR supplemental metadata are handled correctly.27* @modules jdk.localedata28* @run main/othervm -Djava.locale.providers=CLDR Bug817907129*/3031/**32* This fix is dependent on a particular version of CLDR data.33*/3435import java.time.Month;36import java.time.format.TextStyle;37import java.util.Arrays;38import java.util.HashSet;39import java.util.Locale;40import java.util.Map;41import java.util.Set;4243public class Bug8179071 {4445// Deprecated and Legacy tags.46// As of CLDR 38, language aliases for some of the legacy tags have been removed.47private static final Set<String> LegacyAliases = Set.of(48"zh-guoyu", "zh-min-nan", "i-klingon", "i-tsu",49"sgn-CH-DE", "mo", "i-tay", "scc",50"i-hak", "sgn-BE-FR", "i-lux", "tl", "zh-hakka", "i-ami", "aa-SAAHO",51"zh-xiang", "i-pwn", "sgn-BE-NL", "jw", "sh", "i-bnn");52// expected month format data for locales after language aliases replacement.53private static final Map<String, String> shortJanuaryNames = Map.of( "pa-PK", "\u0a1c\u0a28",54"uz-AF" , "yan",55"sr-ME", "\u0458\u0430\u043d",56"scc", "\u0458\u0430\u043d",57"sh", "jan",58"ha-Latn-NE", "Jan",59"i-lux", "Jan.");606162private static void test(String tag, String expected) {63Locale target = Locale.forLanguageTag(tag);64Month day = Month.JANUARY;65TextStyle style = TextStyle.SHORT;66String actual = day.getDisplayName(style, target);67if (!actual.equals(expected)) {68throw new RuntimeException("failed for locale " + tag + " actual output " + actual +" does not match with " + expected);69}70}7172/**73* getAvailableLocales() should not contain any deprecated or Legacy language tags74*/75private static void checkInvalidTags() {76Set<String> invalidTags = new HashSet<>();77Arrays.asList(Locale.getAvailableLocales()).stream()78.map(loc -> loc.toLanguageTag())79.forEach( tag -> {if(LegacyAliases.contains(tag)) {invalidTags.add(tag);}});80if (!invalidTags.isEmpty()) {81throw new RuntimeException("failed: Deprecated and Legacy tags found " + invalidTags + " in AvailableLocales ");82}83}8485public static void main(String[] args) {86shortJanuaryNames.forEach(Bug8179071::test);87checkInvalidTags();88}89}909192