Path: blob/master/test/jdk/sun/util/resources/cldr/Bug8134250.java
41153 views
/*1* Copyright (c) 2015, 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 8134250 813452026* @modules jdk.localedata27* @summary Tests CLDR/LDML features are correctly reflected in JDK.28* @run main/othervm -Djava.locale.providers=CLDR Bug813425029*/3031// Note this test highly depends on a particular version of CLDR. Results32// may vary in the future.3334import java.time.LocalDate;35import java.time.Month;36import java.time.ZoneId;37import java.time.chrono.Chronology;38import java.time.format.DateTimeFormatter;39import java.time.format.DateTimeFormatterBuilder;40import java.time.format.FormatStyle;41import java.time.format.TextStyle;42import java.util.Locale;4344public class Bug8134250 {45public static void main(String [] args) {46LocalDate d = LocalDate.of(1980, Month.JANUARY, 1);4748// en-GB inherits from en-001 where its short tz name for49// America/Los_Angeles is "non-inheritance marker". Thus the50// resulting formatted text should be a custom ID.51DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();52dtfb.appendZoneText(TextStyle.SHORT);53DateTimeFormatter dtf = dtfb.toFormatter(Locale.UK)54.withZone(ZoneId.of("America/Los_Angeles"));55String result = dtf.format(d);56System.out.println(result);57if (!"GMT-08:00".equals(result)) {58throw new RuntimeException("short time zone name for America/Los_Angeles in en_GB is incorrect. Got: " + result + ", expected: GMT-08:00");59}6061// Islamic Um-Alqura calendar is an alias to Islamic calendar.62// In Islamic calendar data, only month names are localized, also63// date/time format for FULL style should be inherited from "generic"64// calendar, where it includes ERA field.65Locale locale = Locale.forLanguageTag("en-US-u-ca-islamic-umalqura");66Chronology chrono = Chronology.ofLocale(locale);67dtf = DateTimeFormatter68.ofLocalizedDate(FormatStyle.FULL)69.withLocale(locale)70.withChronology(chrono);71result = dtf.format(d);72System.out.println(dtf.format(d));73if (!"Tuesday, Safar 12, 1400 AH".equals(result)) {74throw new RuntimeException("FULL date format of Islamic Um-Alqura calendar in en_US is incorrect. Got: " + result + ", expected: Tuesday, Safar 12, 1400 AH");75}76}77}787980