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 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 // These zone ids are new in tzdb and yet to be reflected in 51 // CLDR data. Thus it's assured there is no l10n names for these. 52 // This list is as of CLDR version 29, and should be examined 53 // on the CLDR data upgrade. 54 {"America/Punta_Arenas", Locale.US, "Punta Arenas Standard Time", 55 "GMT-03:00", 56 "Punta Arenas Daylight Time", 57 "GMT-03:00", 58 "Punta Arenas Time", 59 "GMT-03:00"}, 60 {"America/Punta_Arenas", Locale.FRANCE, "Punta Arenas (heure standard)", 61 "UTC\u221203:00", 62 "Punta Arenas (heure d\u2019\u00e9t\u00e9)", 63 "UTC\u221203:00", 64 "heure : Punta Arenas", 65 "UTC\u221203:00"}, 66 {"Asia/Atyrau", Locale.US, "Atyrau Standard Time", 67 "GMT+05:00", 68 "Atyrau Daylight Time", 69 "GMT+05:00", 70 "Atyrau Time", 71 "GMT+05:00"}, 72 {"Asia/Atyrau", Locale.FRANCE, "Atyrau (heure standard)", 73 "UTC+05:00", 74 "Atyrau (heure d\u2019\u00e9t\u00e9)", 75 "UTC+05:00", 76 "heure : Atyrau", 77 "UTC+05:00"}, 78 79 // no "metazone" zones 80 {"Asia/Srednekolymsk", Locale.US, "Srednekolymsk Time", 81 "SRET", 82 "Srednekolymsk Daylight Time", 83 "SREDT", 84 "Srednekolymsk Time", 85 "SRET"}, 86 {"Asia/Srednekolymsk", Locale.FRANCE, "Srednekolymsk (heure standard)", 87 "UTC+11:00", 88 "Srednekolymsk (heure standard)", 89 "UTC+11:00", 90 "heure : Srednekolymsk", 91 "UTC+11:00"}, 92 {"Pacific/Bougainville", Locale.US, "Bougainville Standard Time", 93 "BST", 94 "Bougainville Daylight Time", 95 "BST", 96 "Bougainville Time", 97 "BT"}, 98 {"Pacific/Bougainville", Locale.FRANCE, "Bougainville (heure standard)", 99 "UTC+11:00", 100 "Bougainville (heure standard)", 101 "UTC+11:00", 102 "heure : Bougainville", 103 "UTC+11:00"}, 104 105 }; 106 } 107 108 109 @Test(dataProvider="noResourceTZs") 110 public void test_tzNames(String tzid, Locale locale, String lstd, String sstd, String ldst, String sdst, String lgen, String sgen) { 111 // Standard time 112 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(false, TimeZone.LONG, locale), lstd); 113 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(false, TimeZone.SHORT, locale), sstd); 114 115 // daylight saving time 116 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(true, TimeZone.LONG, locale), ldst); 117 assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(true, TimeZone.SHORT, locale), sdst); 118 119 // generic name 120 assertEquals(ZoneId.of(tzid).getDisplayName(TextStyle.FULL, locale), lgen); 121 assertEquals(ZoneId.of(tzid).getDisplayName(TextStyle.SHORT, locale), sgen); 122 } 123 }