Path: blob/master/test/jdk/java/util/Locale/bcp47u/CalendarTests.java
41153 views
/*1* Copyright (c) 2017, 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*25* @test26* @bug 817684127* @summary Tests Calendar class deals with Unicode extensions28* correctly.29* @modules jdk.localedata30* @run testng/othervm CalendarTests31*/3233import static org.testng.Assert.assertEquals;3435import java.text.DateFormat;36import java.util.Calendar;37import java.util.Locale;38import java.util.TimeZone;3940import org.testng.annotations.AfterTest;41import org.testng.annotations.BeforeTest;42import org.testng.annotations.DataProvider;43import org.testng.annotations.Test;4445/**46* Test Calendar with BCP47 U extensions47*/48@Test49public class CalendarTests {50private static TimeZone defaultTZ;5152private static final TimeZone ASIATOKYO = TimeZone.getTimeZone("Asia/Tokyo");53private static final TimeZone AMLA = TimeZone.getTimeZone("America/Los_Angeles");5455private static final Locale JPTYO = Locale.forLanguageTag("en-u-tz-jptyo");56private static final Locale USLAX = Locale.forLanguageTag("en-u-tz-uslax");5758private static final Locale FW_SUN = Locale.forLanguageTag("en-US-u-fw-sun");59private static final Locale FW_MON = Locale.forLanguageTag("en-US-u-fw-mon");60private static final Locale FW_TUE = Locale.forLanguageTag("en-US-u-fw-tue");61private static final Locale FW_WED = Locale.forLanguageTag("en-US-u-fw-wed");62private static final Locale FW_THU = Locale.forLanguageTag("en-US-u-fw-thu");63private static final Locale FW_FRI = Locale.forLanguageTag("en-US-u-fw-fri");64private static final Locale FW_SAT = Locale.forLanguageTag("en-US-u-fw-sat");6566@BeforeTest67public void beforeTest() {68defaultTZ = TimeZone.getDefault();69TimeZone.setDefault(AMLA);70}7172@AfterTest73public void afterTest() {74TimeZone.setDefault(defaultTZ);75}7677@DataProvider(name="tz")78Object[][] tz() {79return new Object[][] {80// Locale, Expected Zone,81{JPTYO, ASIATOKYO},82{USLAX, AMLA},8384// invalid85{Locale.forLanguageTag("en-US-u-tz-jpzzz"), AMLA}86};87}8889@DataProvider(name="firstDayOfWeek")90Object[][] firstDayOfWeek () {91return new Object[][] {92// Locale, Expected DayOfWeek,93{Locale.US, Calendar.SUNDAY},94{FW_SUN, Calendar.SUNDAY},95{FW_MON, Calendar.MONDAY},96{FW_TUE, Calendar.TUESDAY},97{FW_WED, Calendar.WEDNESDAY},98{FW_THU, Calendar.THURSDAY},99{FW_FRI, Calendar.FRIDAY},100{FW_SAT, Calendar.SATURDAY},101102// invalid case103{Locale.forLanguageTag("en-US-u-fw-xxx"), Calendar.SUNDAY},104105// region override106{Locale.forLanguageTag("en-US-u-rg-gbzzzz"), Calendar.MONDAY},107{Locale.forLanguageTag("zh-CN-u-rg-eszzzz"), Calendar.MONDAY},108109// "fw" and "rg".110{Locale.forLanguageTag("en-US-u-fw-wed-rg-gbzzzz"), Calendar.WEDNESDAY},111{Locale.forLanguageTag("en-US-u-fw-xxx-rg-gbzzzz"), Calendar.MONDAY},112{Locale.forLanguageTag("en-US-u-fw-xxx-rg-zzzz"), Calendar.SUNDAY},113};114}115116@DataProvider(name="minDaysInFirstWeek")117Object[][] minDaysInFrstWeek () {118return new Object[][] {119// Locale, Expected minDay,120{Locale.US, 1},121122// region override123{Locale.forLanguageTag("en-US-u-rg-gbzzzz"), 4},124{Locale.forLanguageTag("zh-CN-u-rg-eszzzz"), 4},125};126}127128@Test(dataProvider="tz")129public void test_tz(Locale locale, TimeZone zoneExpected) {130DateFormat df = DateFormat.getTimeInstance(DateFormat.FULL, locale);131assertEquals(df.getTimeZone(), zoneExpected);132133Calendar c = Calendar.getInstance(locale);134assertEquals(c.getTimeZone(), zoneExpected);135136c = new Calendar.Builder().setLocale(locale).build();137assertEquals(c.getTimeZone(), zoneExpected);138}139140@Test(dataProvider="firstDayOfWeek")141public void test_firstDayOfWeek(Locale locale, int dowExpected) {142Calendar c = Calendar.getInstance(locale);143assertEquals(c.getFirstDayOfWeek(), dowExpected);144145c = new Calendar.Builder().setLocale(locale).build();146assertEquals(c.getFirstDayOfWeek(), dowExpected);147}148149@Test(dataProvider="minDaysInFirstWeek")150public void test_minDaysInFirstWeek(Locale locale, int minDaysExpected) {151Calendar c = Calendar.getInstance(locale);152assertEquals(c.getMinimalDaysInFirstWeek(), minDaysExpected);153154c = new Calendar.Builder().setLocale(locale).build();155assertEquals(c.getMinimalDaysInFirstWeek(), minDaysExpected);156}157}158159160