test/jdk/java/util/Calendar/CalendarDataTest.java
changeset 50576 374bd919d8fe
parent 48251 57148c79bd75
child 54769 925ee7a89325
equal deleted inserted replaced
50575:72c694f035ee 50576:374bd919d8fe
     1 /*
     1 /*
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 8190918
    26  * @bug 8190918 8202537
    27  * @summary Tests for region dependent calendar data, i.e.,
    27  * @summary Tests for region dependent calendar data, i.e.,
    28  *      firstDayOfWeek and minimalDaysInFirstWeek.
    28  *      firstDayOfWeek and minimalDaysInFirstWeek.
    29  * @modules jdk.localedata
    29  * @modules jdk.localedata
    30  * @run main CalendarDataTest
    30  * @run main CalendarDataTest
    31  */
    31  */
    38 
    38 
    39 public class CalendarDataTest {
    39 public class CalendarDataTest {
    40 
    40 
    41     // golden data from CLDR
    41     // golden data from CLDR
    42     private static final List<List<String>> FIRSTDAYDATA = List.of(
    42     private static final List<List<String>> FIRSTDAYDATA = List.of(
    43         List.of("1", "AG AR AS AU BR BS BT BW BZ CA CN CO DM DO ET GT " +
    43         List.of("1", "AG AR AS AU BD BR BS BT BW BZ CA CN CO DM DO ET GT " +
    44             "GU HK HN ID IE IL IN JM JP KE KH KR LA MH MM MO MT MX MZ " +
    44             "GU HK HN ID IE IL IN JM JP KE KH KR LA MH MM MO MT MX MZ " +
    45             "NI NP NZ PA PE PH PK PR PY SA SG SV TH TN TT TW UM US VE " +
    45             "NI NP PA PE PH PK PR PY SA SG SV TH TN TT TW UM US VE " +
    46             "VI WS YE ZA ZW"),
    46             "VI WS YE ZA ZW"),
    47         List.of("2",   "001 AD AI AL AM AN AT AX AZ BA BE BG BM BN BY " +
    47         List.of("2",   "001 AD AI AL AM AN AT AX AZ BA BE BG BM BN BY " +
    48             "CH CL CM CR CY CZ DE DK EC EE ES FI FJ FO FR GB GE GF GP " +
    48             "CH CL CM CR CY CZ DE DK EC EE ES FI FJ FO FR GB GE GF GP " +
    49             "GR HR HU IS IT KG KZ LB LI LK LT LU LV MC MD ME MK MN MQ " +
    49             "GR HR HU IS IT KG KZ LB LI LK LT LU LV MC MD ME MK MN MQ " +
    50             "MY NL NO PL PT RE RO RS RU SE SI SK SM TJ TM TR UA UY UZ " +
    50             "MY NL NO NZ PL PT RE RO RU RS SE SI SK SM TJ TM TR UA UY UZ " +
    51             "VA VN XK"),
    51             "VA VN XK"),
    52         List.of("6", "BD MV"),
    52         List.of("6", "MV"),
    53         List.of("7", "AE AF BH DJ DZ EG IQ IR JO KW LY MA OM QA SD SY"));
    53         List.of("7", "AE AF BH DJ DZ EG IQ IR JO KW LY MA OM QA SD SY"));
    54 
    54 
    55     private static final List<List<String>> MINDAYSDATA = List.of(
    55     private static final List<List<String>> MINDAYSDATA = List.of(
    56         List.of("1", "001 GU UM US VI"),
    56         List.of("1", "001 GU UM US VI"),
    57         List.of("4", "AD AN AT AX BE BG CH CZ DE DK EE ES FI FJ FO FR " +
    57         List.of("4", "AD AN AT AX BE BG CH CZ DE DK EE ES FI FJ FO FR " +
    58             "GB GF GG GI GP GR HU IE IM IS IT JE LI LT LU MC MQ NL NO " +
    58             "GB GF GG GI GP GR HU IE IM IS IT JE LI LT LU MC MQ NL NO " +
    59             "PL PT RE SE SJ SK SM VA"));
    59             "PL PT RE RU SE SJ SK SM VA"));
    60 
    60 
    61     public static void main(String... args) throws Exception {
    61     public static void main(String... args) throws Exception {
    62         // world
    62         // world
    63         Calendar cal = Calendar.getInstance(new Locale("", "001"));
    63         Calendar cal = Calendar.getInstance(new Locale("", "001"));
    64         checkResult("001",
    64         checkResult("001",
    93         expected = Integer.parseInt(findEntry(region, MINDAYSDATA)
    93         expected = Integer.parseInt(findEntry(region, MINDAYSDATA)
    94             .orElse(findEntry("001", MINDAYSDATA).orElse(List.of("1")))
    94             .orElse(findEntry("001", MINDAYSDATA).orElse(List.of("1")))
    95             .get(0));
    95             .get(0));
    96         if (minDays != expected) {
    96         if (minDays != expected) {
    97             throw new RuntimeException("minimalDaysInFirstWeek is incorrect for the region: " +
    97             throw new RuntimeException("minimalDaysInFirstWeek is incorrect for the region: " +
    98                     region + ". Returned: " + firstDay + ", Expected: " + expected);
    98                     region + ". Returned: " + minDays + ", Expected: " + expected);
    99         }
    99         }
   100     }
   100     }
   101 
   101 
   102     private static Optional<List<String>> findEntry(String region, List<List<String>> data) {
   102     private static Optional<List<String>> findEntry(String region, List<List<String>> data) {
   103         return data.stream()
   103         return data.stream()