1 /*
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
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
26 * @bug 8181157 8202537
27 * @modules jdk.localedata
28 * @summary Checks CLDR time zone names are generated correctly at runtime
29 * @run testng/othervm -Djava.locale.providers=CLDR TimeZoneNamesTest
30 */
31
32 import static org.testng.Assert.assertEquals;
33
34 import java.time.ZoneId;
35 import java.time.format.TextStyle;
36 import java.util.Locale;
37 import java.util.TimeZone;
38
39 import org.testng.annotations.DataProvider;
40 import org.testng.annotations.Test;
41
42 @Test
43 public class TimeZoneNamesTest {
44
45 @DataProvider(name="noResourceTZs")
46 Object[][] data() {
47 return new Object[][] {
48 // tzid, locale, style, expected
49
50 // This list is as of CLDR version 33, and should be examined
51 // on the CLDR data upgrade.
52
53 // no "metazone" zones
54 {"Asia/Srednekolymsk", Locale.US, "Srednekolymsk Time",
55 "SRET",
56 "Srednekolymsk Daylight Time",
57 "SREDT",
58 "Srednekolymsk Time",
59 "SRET"},
60 {"Asia/Srednekolymsk", Locale.FRANCE, "Srednekolymsk (heure standard)",
61 "UTC+11:00",
62 "Srednekolymsk (heure standard)",
63 "UTC+11:00",
64 "heure : Srednekolymsk",
65 "UTC+11:00"},
66 {"America/Punta_Arenas", Locale.US, "Punta Arenas Standard Time",
67 "GMT-03:00",
68 "Punta Arenas Standard Time",
69 "GMT-03:00",
70 "Punta Arenas Time",
71 "GMT-03:00"},
72 {"America/Punta_Arenas", Locale.FRANCE, "Punta Arenas (heure standard)",
73 "UTC\u221203:00",
74 "Punta Arenas (heure standard)",
75 "UTC\u221203:00",
76 "heure : Punta Arenas",
77 "UTC\u221203:00"},
78 {"Asia/Famagusta", Locale.US, "Eastern European Time",
79 "EET",
80 "Eastern European Summer Time",
81 "EEST",
82 "Eastern European Time",
83 "EET"},
84 {"Asia/Famagusta", Locale.FRANCE, "Famagouste (heure standard)",
85 "UTC+02:00",
86 "Famagouste (heure standard)",
87 "UTC+03:00",
88 "heure : Famagouste",
89 "UTC+02:00"},
90 {"Europe/Astrakhan", Locale.US, "Astrakhan Standard Time",
91 "GMT+04:00",
92 "Astrakhan Standard Time",
93 "GMT+04:00",
94 "Astrakhan Time",
95 "GMT+04:00"},
96 {"Europe/Astrakhan", Locale.FRANCE, "Astrakhan (heure standard)",
97 "UTC+04:00",
98 "Astrakhan (heure standard)",
99 "UTC+04:00",
100 "heure : Astrakhan",
101 "UTC+04:00"},
102 {"Europe/Saratov", Locale.US, "Saratov Standard Time",
103 "GMT+04:00",
104 "Saratov Standard Time",
105 "GMT+04:00",
106 "Saratov Time",
107 "GMT+04:00"},
108 {"Europe/Saratov", Locale.FRANCE, "Saratov (heure standard)",
109 "UTC+04:00",
110 "Saratov (heure standard)",
111 "UTC+04:00",
112 "heure : Saratov",
113 "UTC+04:00"},
114 {"Europe/Ulyanovsk", Locale.US, "Ulyanovsk Standard Time",
115 "GMT+04:00",
116 "Ulyanovsk Standard Time",
117 "GMT+04:00",
118 "Ulyanovsk Time",
119 "GMT+04:00"},
120 {"Europe/Ulyanovsk", Locale.FRANCE, "Oulianovsk (heure standard)",
121 "UTC+04:00",
122 "Oulianovsk (heure standard)",
123 "UTC+04:00",
124 "heure : Oulianovsk",
125 "UTC+04:00"},
126 {"Pacific/Bougainville", Locale.US, "Bougainville Standard Time",
127 "BST",
128 "Bougainville Daylight Time",
129 "BST",
130 "Bougainville Time",
131 "BT"},
132 {"Pacific/Bougainville", Locale.FRANCE, "Bougainville (heure standard)",
133 "UTC+11:00",
134 "Bougainville (heure standard)",
135 "UTC+11:00",
136 "heure : Bougainville",
137 "UTC+11:00"},
138
139 };
140 }
141
142
143 @Test(dataProvider="noResourceTZs")
144 public void test_tzNames(String tzid, Locale locale, String lstd, String sstd, String ldst, String sdst, String lgen, String sgen) {
145 // Standard time
146 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(false, TimeZone.LONG, locale), lstd);
147 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(false, TimeZone.SHORT, locale), sstd);
148
149 // daylight saving time
150 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(true, TimeZone.LONG, locale), ldst);
151 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(true, TimeZone.SHORT, locale), sdst);
152
153 // generic name
154 assertEquals(ZoneId.of(tzid).getDisplayName(TextStyle.FULL, locale), lgen);
155 assertEquals(ZoneId.of(tzid).getDisplayName(TextStyle.SHORT, locale), sgen);
156 }
157 }
|
1 /*
2 * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
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
26 * @bug 8181157 8202537 8234347 8236548
27 * @modules jdk.localedata
28 * @summary Checks CLDR time zone names are generated correctly at runtime
29 * @run testng/othervm -Djava.locale.providers=CLDR TimeZoneNamesTest
30 */
31
32 import java.text.DateFormatSymbols;
33 import java.time.ZoneId;
34 import java.time.format.TextStyle;
35 import java.util.Arrays;
36 import java.util.Locale;
37 import java.util.Objects;
38 import java.util.TimeZone;
39
40 import static org.testng.Assert.assertEquals;
41 import static org.testng.Assert.assertFalse;
42 import org.testng.annotations.DataProvider;
43 import org.testng.annotations.Test;
44
45 @Test
46 public class TimeZoneNamesTest {
47
48 @DataProvider(name="noResourceTZs")
49 Object[][] data() {
50 return new Object[][] {
51 // tzid, locale, style, expected
52
53 // This list is as of CLDR version 33, and should be examined
54 // on the CLDR data upgrade.
55
56 // no "metazone" zones
57 {"Asia/Srednekolymsk", Locale.US, "Srednekolymsk Standard Time",
58 "GMT+11:00",
59 "Srednekolymsk Daylight Time",
60 "GMT+11:00",
61 "Srednekolymsk Time",
62 "GMT+11:00"},
63 {"Asia/Srednekolymsk", Locale.FRANCE, "Srednekolymsk (heure standard)",
64 "UTC+11:00",
65 "Srednekolymsk (heure d\u2019\u00e9t\u00e9)",
66 "UTC+11:00",
67 "heure : Srednekolymsk",
68 "UTC+11:00"},
69 {"America/Punta_Arenas", Locale.US, "Punta Arenas Standard Time",
70 "GMT-03:00",
71 "Punta Arenas Daylight Time",
72 "GMT-03:00",
73 "Punta Arenas Time",
74 "GMT-03:00"},
75 {"America/Punta_Arenas", Locale.FRANCE, "Punta Arenas (heure standard)",
76 "UTC\u221203:00",
77 "Punta Arenas (heure d\u2019\u00e9t\u00e9)",
78 "UTC\u221203:00",
79 "heure : Punta Arenas",
80 "UTC\u221203:00"},
81 {"Asia/Famagusta", Locale.US, "Famagusta Standard Time",
82 "GMT+02:00",
83 "Famagusta Daylight Time",
84 "GMT+03:00",
85 "Famagusta Time",
86 "GMT+02:00"},
87 {"Asia/Famagusta", Locale.FRANCE, "Famagouste (heure standard)",
88 "UTC+02:00",
89 "Famagouste (heure d\u2019\u00e9t\u00e9)",
90 "UTC+03:00",
91 "heure : Famagouste",
92 "UTC+02:00"},
93 {"Europe/Astrakhan", Locale.US, "Astrakhan Standard Time",
94 "GMT+04:00",
95 "Astrakhan Daylight Time",
96 "GMT+04:00",
97 "Astrakhan Time",
98 "GMT+04:00"},
99 {"Europe/Astrakhan", Locale.FRANCE, "Astrakhan (heure standard)",
100 "UTC+04:00",
101 "Astrakhan (heure d\u2019\u00e9t\u00e9)",
102 "UTC+04:00",
103 "heure : Astrakhan",
104 "UTC+04:00"},
105 {"Europe/Saratov", Locale.US, "Saratov Standard Time",
106 "GMT+04:00",
107 "Saratov Daylight Time",
108 "GMT+04:00",
109 "Saratov Time",
110 "GMT+04:00"},
111 {"Europe/Saratov", Locale.FRANCE, "Saratov (heure standard)",
112 "UTC+04:00",
113 "Saratov (heure d\u2019\u00e9t\u00e9)",
114 "UTC+04:00",
115 "heure : Saratov",
116 "UTC+04:00"},
117 {"Europe/Ulyanovsk", Locale.US, "Ulyanovsk Standard Time",
118 "GMT+04:00",
119 "Ulyanovsk Daylight Time",
120 "GMT+04:00",
121 "Ulyanovsk Time",
122 "GMT+04:00"},
123 {"Europe/Ulyanovsk", Locale.FRANCE, "Oulianovsk (heure standard)",
124 "UTC+04:00",
125 "Oulianovsk (heure d\u2019\u00e9t\u00e9)",
126 "UTC+04:00",
127 "heure : Oulianovsk",
128 "UTC+04:00"},
129 {"Pacific/Bougainville", Locale.US, "Bougainville Standard Time",
130 "GMT+11:00",
131 "Bougainville Daylight Time",
132 "GMT+11:00",
133 "Bougainville Time",
134 "GMT+11:00"},
135 {"Pacific/Bougainville", Locale.FRANCE, "Bougainville (heure standard)",
136 "UTC+11:00",
137 "Bougainville (heure d\u2019\u00e9t\u00e9)",
138 "UTC+11:00",
139 "heure : Bougainville",
140 "UTC+11:00"},
141 {"Europe/Istanbul", Locale.US, "Istanbul Standard Time",
142 "GMT+03:00",
143 "Istanbul Daylight Time",
144 "GMT+03:00",
145 "Istanbul Time",
146 "GMT+03:00"},
147 {"Europe/Istanbul", Locale.FRANCE, "Istanbul (heure standard)",
148 "UTC+03:00",
149 "Istanbul (heure d\u2019\u00e9t\u00e9)",
150 "UTC+03:00",
151 "heure : Istanbul",
152 "UTC+03:00"},
153 {"Asia/Istanbul", Locale.US, "Istanbul Standard Time",
154 "GMT+03:00",
155 "Istanbul Daylight Time",
156 "GMT+03:00",
157 "Istanbul Time",
158 "GMT+03:00"},
159 {"Asia/Istanbul", Locale.FRANCE, "Istanbul (heure standard)",
160 "UTC+03:00",
161 "Istanbul (heure d\u2019\u00e9t\u00e9)",
162 "UTC+03:00",
163 "heure : Istanbul",
164 "UTC+03:00"},
165 {"Turkey", Locale.US, "Istanbul Standard Time",
166 "GMT+03:00",
167 "Istanbul Daylight Time",
168 "GMT+03:00",
169 "Istanbul Time",
170 "GMT+03:00"},
171 {"Turkey", Locale.FRANCE, "Istanbul (heure standard)",
172 "UTC+03:00",
173 "Istanbul (heure d\u2019\u00e9t\u00e9)",
174 "UTC+03:00",
175 "heure : Istanbul",
176 "UTC+03:00"},
177 };
178 }
179
180
181 @Test(dataProvider="noResourceTZs")
182 public void test_tzNames(String tzid, Locale locale, String lstd, String sstd, String ldst, String sdst, String lgen, String sgen) {
183 // Standard time
184 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(false, TimeZone.LONG, locale), lstd);
185 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(false, TimeZone.SHORT, locale), sstd);
186
187 // daylight saving time
188 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(true, TimeZone.LONG, locale), ldst);
189 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(true, TimeZone.SHORT, locale), sdst);
190
191 // generic name
192 assertEquals(ZoneId.of(tzid).getDisplayName(TextStyle.FULL, locale), lgen);
193 assertEquals(ZoneId.of(tzid).getDisplayName(TextStyle.SHORT, locale), sgen);
194 }
195
196 // Make sure getZoneStrings() returns non-empty string array
197 @Test
198 public void test_getZoneStrings() {
199 assertFalse(
200 Arrays.stream(Locale.getAvailableLocales())
201 .peek(l -> System.out.println("Locale: " + l))
202 .map(l -> DateFormatSymbols.getInstance(l).getZoneStrings())
203 .flatMap(zs -> Arrays.stream(zs))
204 .peek(names -> System.out.println(" tz: " + names[0]))
205 .flatMap(names -> Arrays.stream(names))
206 .filter(name -> Objects.isNull(name) || name.isEmpty())
207 .findAny()
208 .isPresent(),
209 "getZoneStrings() returned array containing non-empty string element(s)");
210 }
211 }
|