Path: blob/master/test/jdk/sun/util/resources/cldr/TimeZoneNamesTest.java
41153 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8181157 8202537 8234347 8236548 826127926* @modules jdk.localedata27* @summary Checks CLDR time zone names are generated correctly at runtime28* @run testng/othervm -Djava.locale.providers=CLDR TimeZoneNamesTest29*/3031import java.text.DateFormatSymbols;32import java.time.ZoneId;33import java.time.format.TextStyle;34import java.util.Arrays;35import java.util.Locale;36import java.util.Objects;37import java.util.TimeZone;3839import static org.testng.Assert.assertEquals;40import static org.testng.Assert.assertFalse;41import org.testng.annotations.DataProvider;42import org.testng.annotations.Test;4344@Test45public class TimeZoneNamesTest {4647@DataProvider(name="noResourceTZs")48Object[][] data() {49return new Object[][] {50// tzid, locale, style, expected5152// This list is as of CLDR version 33, and should be examined53// on the CLDR data upgrade.5455// no "metazone" zones56{"Asia/Srednekolymsk", Locale.US, "Srednekolymsk Standard Time",57"GMT+11:00",58"Srednekolymsk Daylight Time",59"GMT+11:00",60"Srednekolymsk Time",61"GMT+11:00"},62{"Asia/Srednekolymsk", Locale.FRANCE, "Srednekolymsk (heure standard)",63"UTC+11:00",64"Srednekolymsk (heure d\u2019\u00e9t\u00e9)",65"UTC+11:00",66"heure : Srednekolymsk",67"UTC+11:00"},68{"America/Punta_Arenas", Locale.US, "Punta Arenas Standard Time",69"GMT-03:00",70"Punta Arenas Daylight Time",71"GMT-03:00",72"Punta Arenas Time",73"GMT-03:00"},74{"America/Punta_Arenas", Locale.FRANCE, "Punta Arenas (heure standard)",75"UTC\u221203:00",76"Punta Arenas (heure d\u2019\u00e9t\u00e9)",77"UTC\u221203:00",78"heure : Punta Arenas",79"UTC\u221203:00"},80{"Asia/Famagusta", Locale.US, "Famagusta Standard Time",81"GMT+02:00",82"Famagusta Daylight Time",83"GMT+03:00",84"Famagusta Time",85"GMT+02:00"},86{"Asia/Famagusta", Locale.FRANCE, "Famagouste (heure standard)",87"UTC+02:00",88"Famagouste (heure d\u2019\u00e9t\u00e9)",89"UTC+03:00",90"heure : Famagouste",91"UTC+02:00"},92{"Europe/Astrakhan", Locale.US, "Astrakhan Standard Time",93"GMT+04:00",94"Astrakhan Daylight Time",95"GMT+04:00",96"Astrakhan Time",97"GMT+04:00"},98{"Europe/Astrakhan", Locale.FRANCE, "Astrakhan (heure standard)",99"UTC+04:00",100"Astrakhan (heure d\u2019\u00e9t\u00e9)",101"UTC+04:00",102"heure : Astrakhan",103"UTC+04:00"},104{"Europe/Saratov", Locale.US, "Saratov Standard Time",105"GMT+04:00",106"Saratov Daylight Time",107"GMT+04:00",108"Saratov Time",109"GMT+04:00"},110{"Europe/Saratov", Locale.FRANCE, "Saratov (heure standard)",111"UTC+04:00",112"Saratov (heure d\u2019\u00e9t\u00e9)",113"UTC+04:00",114"heure : Saratov",115"UTC+04:00"},116{"Europe/Ulyanovsk", Locale.US, "Ulyanovsk Standard Time",117"GMT+04:00",118"Ulyanovsk Daylight Time",119"GMT+04:00",120"Ulyanovsk Time",121"GMT+04:00"},122{"Europe/Ulyanovsk", Locale.FRANCE, "Oulianovsk (heure standard)",123"UTC+04:00",124"Oulianovsk (heure d\u2019\u00e9t\u00e9)",125"UTC+04:00",126"heure : Oulianovsk",127"UTC+04:00"},128{"Pacific/Bougainville", Locale.US, "Bougainville Standard Time",129"GMT+11:00",130"Bougainville Daylight Time",131"GMT+11:00",132"Bougainville Time",133"GMT+11:00"},134{"Pacific/Bougainville", Locale.FRANCE, "Bougainville (heure standard)",135"UTC+11:00",136"Bougainville (heure d\u2019\u00e9t\u00e9)",137"UTC+11:00",138"heure : Bougainville",139"UTC+11:00"},140{"Europe/Istanbul", Locale.US, "Istanbul Standard Time",141"GMT+03:00",142"Istanbul Daylight Time",143"GMT+03:00",144"Istanbul Time",145"GMT+03:00"},146{"Europe/Istanbul", Locale.FRANCE, "Istanbul (heure standard)",147"UTC+03:00",148"Istanbul (heure d\u2019\u00e9t\u00e9)",149"UTC+03:00",150"heure : Istanbul",151"UTC+03:00"},152{"Asia/Istanbul", Locale.US, "Istanbul Standard Time",153"GMT+03:00",154"Istanbul Daylight Time",155"GMT+03:00",156"Istanbul Time",157"GMT+03:00"},158{"Asia/Istanbul", Locale.FRANCE, "Istanbul (heure standard)",159"UTC+03:00",160"Istanbul (heure d\u2019\u00e9t\u00e9)",161"UTC+03:00",162"heure : Istanbul",163"UTC+03:00"},164{"Turkey", Locale.US, "Istanbul Standard Time",165"GMT+03:00",166"Istanbul Daylight Time",167"GMT+03:00",168"Istanbul Time",169"GMT+03:00"},170{"Turkey", Locale.FRANCE, "Istanbul (heure standard)",171"UTC+03:00",172"Istanbul (heure d\u2019\u00e9t\u00e9)",173"UTC+03:00",174"heure : Istanbul",175"UTC+03:00"},176};177}178179180@Test(dataProvider="noResourceTZs")181public void test_tzNames(String tzid, Locale locale, String lstd, String sstd, String ldst, String sdst, String lgen, String sgen) {182// Standard time183assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(false, TimeZone.LONG, locale), lstd);184assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(false, TimeZone.SHORT, locale), sstd);185186// daylight saving time187assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(true, TimeZone.LONG, locale), ldst);188assertEquals(TimeZone.getTimeZone(tzid).getDisplayName(true, TimeZone.SHORT, locale), sdst);189190// generic name191assertEquals(ZoneId.of(tzid).getDisplayName(TextStyle.FULL, locale), lgen);192assertEquals(ZoneId.of(tzid).getDisplayName(TextStyle.SHORT, locale), sgen);193}194195// Make sure getZoneStrings() returns non-empty string array196@Test197public void test_getZoneStrings() {198assertFalse(199Arrays.stream(Locale.getAvailableLocales())200.limit(30)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}212213214