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 }