48251
|
1 |
/*
|
54769
|
2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
48251
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
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
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @test
|
58825
|
26 |
* @bug 8190918 8202537 8221432 8231273
|
48251
|
27 |
* @summary Tests for region dependent calendar data, i.e.,
|
|
28 |
* firstDayOfWeek and minimalDaysInFirstWeek.
|
|
29 |
* @modules jdk.localedata
|
|
30 |
* @run main CalendarDataTest
|
|
31 |
*/
|
|
32 |
|
|
33 |
import java.util.Calendar;
|
|
34 |
import java.util.List;
|
|
35 |
import java.util.Locale;
|
|
36 |
import java.util.Optional;
|
|
37 |
import java.util.stream.IntStream;
|
|
38 |
|
|
39 |
public class CalendarDataTest {
|
|
40 |
|
|
41 |
// golden data from CLDR
|
|
42 |
private static final List<List<String>> FIRSTDAYDATA = List.of(
|
58825
|
43 |
List.of("1", "AG AS AU BD BR BS BT BW BZ CA CN CO DM DO ET GT " +
|
54769
|
44 |
"GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ " +
|
|
45 |
"NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE " +
|
48251
|
46 |
"VI WS YE ZA ZW"),
|
58825
|
47 |
List.of("2", "001 AD AI AL AM AN AR AT AX AZ BA BE BG BM BN BY " +
|
48251
|
48 |
"CH CL CM CR CY CZ DE DK EC EE ES FI FJ FO FR GB GE GF GP " +
|
58825
|
49 |
"GR HR HU IE IS IT KG KZ LB LI LK LT LU LV MC MD ME MK MN MQ " +
|
|
50 |
"MY NL NO NZ PL RE RO RS RU SE SI SK SM TJ TM TR UA UY UZ " +
|
48251
|
51 |
"VA VN XK"),
|
50576
|
52 |
List.of("6", "MV"),
|
54769
|
53 |
List.of("7", "AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY"));
|
48251
|
54 |
|
|
55 |
private static final List<List<String>> MINDAYSDATA = List.of(
|
|
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 " +
|
|
58 |
"GB GF GG GI GP GR HU IE IM IS IT JE LI LT LU MC MQ NL NO " +
|
50576
|
59 |
"PL PT RE RU SE SJ SK SM VA"));
|
48251
|
60 |
|
|
61 |
public static void main(String... args) throws Exception {
|
|
62 |
// world
|
|
63 |
Calendar cal = Calendar.getInstance(new Locale("", "001"));
|
|
64 |
checkResult("001",
|
|
65 |
cal.getFirstDayOfWeek(),
|
|
66 |
cal.getMinimalDaysInFirstWeek());
|
|
67 |
|
|
68 |
// two letter country codes
|
|
69 |
IntStream.range(0x41, 0x5b)
|
|
70 |
.forEach(c1 -> {
|
|
71 |
IntStream.range(0x41, 0x5b)
|
|
72 |
.mapToObj(c2 -> String.valueOf((char)c1) + String.valueOf((char)c2))
|
|
73 |
.forEach(region -> {
|
|
74 |
Calendar c = Calendar.getInstance(new Locale("", region));
|
|
75 |
checkResult(region,
|
|
76 |
c.getFirstDayOfWeek(),
|
|
77 |
c.getMinimalDaysInFirstWeek());
|
|
78 |
});
|
|
79 |
});
|
|
80 |
}
|
|
81 |
|
|
82 |
private static void checkResult(String region, int firstDay, int minDays) {
|
|
83 |
// first day of week
|
|
84 |
int expected = Integer.parseInt(findEntry(region, FIRSTDAYDATA)
|
|
85 |
.orElse(findEntry("001", FIRSTDAYDATA).orElse(List.of("1")))
|
|
86 |
.get(0));
|
|
87 |
if (firstDay != expected) {
|
|
88 |
throw new RuntimeException("firstDayOfWeek is incorrect for the region: " +
|
|
89 |
region + ". Returned: " + firstDay + ", Expected: " + expected);
|
|
90 |
}
|
|
91 |
|
|
92 |
// minimal days in first week
|
|
93 |
expected = Integer.parseInt(findEntry(region, MINDAYSDATA)
|
|
94 |
.orElse(findEntry("001", MINDAYSDATA).orElse(List.of("1")))
|
|
95 |
.get(0));
|
|
96 |
if (minDays != expected) {
|
|
97 |
throw new RuntimeException("minimalDaysInFirstWeek is incorrect for the region: " +
|
50576
|
98 |
region + ". Returned: " + minDays + ", Expected: " + expected);
|
48251
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
private static Optional<List<String>> findEntry(String region, List<List<String>> data) {
|
|
103 |
return data.stream()
|
|
104 |
.filter(l -> l.get(1).contains(region))
|
|
105 |
.findAny();
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|