Path: blob/master/test/jdk/java/util/PluggableLocale/CalendarDataProviderTest.java
41149 views
/*1* Copyright (c) 2012, 2018, 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 7058207 8000986 8062588 821040626* @summary CalendarDataProvider tests27* @library providersrc/foobarutils28* providersrc/barprovider29* @build com.foobar.Utils30* com.bar.*31* @run main/othervm -Djava.locale.providers=JRE,SPI CalendarDataProviderTest32*/3334import java.util.Calendar;35import java.util.Locale;3637import static java.util.Calendar.WEDNESDAY;3839/**40* Test case for CalendarDataProvider.41*42* Test strategy:43* com.bar.CalendarDataProviderImpl supports only ja_JP_kids locale. It returns44* unusual week parameter values, WEDNESDAY - first day of week, 7 - minimal45* days in the first week.46*47* A Calendar instance created with ja_JP_kids should use the week parameters48* provided by com.bar.CalendarDataProviderImpl.49*/50public class CalendarDataProviderTest {5152public static void main(String[] s) {53new CalendarDataProviderTest().test();54}5556void test() {57Locale kids = new Locale("ja", "JP", "kids"); // test provider's supported locale58Calendar kcal = Calendar.getInstance(kids);5960// check the week parameters61checkResult("firstDayOfWeek", kcal.getFirstDayOfWeek(), WEDNESDAY);62checkResult("minimalDaysInFirstWeek", kcal.getMinimalDaysInFirstWeek(), 7);63}6465private <T> void checkResult(String msg, T got, T expected) {66if (!expected.equals(got)) {67String s = String.format("%s: got='%s', expected='%s'", msg, got, expected);68throw new RuntimeException(s);69}70}71}7273