1 import java.util.TimeZone;
   2 
   3 /*
   4  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * @test
  28  * @bug 8234288
  29  * @modules jdk.localedata
  30  * @summary updating time zone strings for Turkey Time
  31  * @run main/othervm -Djava.locale.providers=JRE,SPI Bug8234288
  32  */
  33 
  34 import java.util.Locale;
  35 import java.util.TimeZone;
  36 
  37 public class Bug8234288 {
  38     private static Locale ENGLISH = new Locale("en");
  39     private static String ZONE_EUROPE_ISTANBUL = "Europe/Istanbul";
  40     private static String ZONE_ASIA_ISTANBUL = "Asia/Istanbul";
  41     private static String ZONE_TURKEY = "Turkey";
  42 
  43     private static String EXPECTED_TRT_LONG = "Turkey Time";
  44     private static String EXPECTED_TRT_SHORT = "TRT";
  45     private static String EXPECTED_TRST_LONG = "Turkey Summer Time";
  46     private static String EXPECTED_TRST_SHORT = "TRST";
  47 
  48     public static void main(String[] arg) {
  49         int errors = testTurkeyTimeZone(ZONE_EUROPE_ISTANBUL)
  50                     + testTurkeyTimeZone(ZONE_ASIA_ISTANBUL)
  51                     + testTurkeyTimeZone(ZONE_TURKEY);
  52 
  53         if (errors > 0) {
  54             throw new RuntimeException();
  55         }
  56     }
  57 
  58     private static int testTurkeyTimeZone(final String location) {
  59         return testTimeZone(location, false, TimeZone.LONG, EXPECTED_TRT_LONG)
  60              + testTimeZone(location, false, TimeZone.SHORT, EXPECTED_TRT_SHORT)
  61              + testTimeZone(location, true, TimeZone.LONG, EXPECTED_TRST_LONG)
  62              + testTimeZone(location, true, TimeZone.SHORT, EXPECTED_TRST_SHORT);
  63     }
  64 
  65     private static int testTimeZone(final String location, final boolean isSummerTime,
  66                                     final int style, final String expected) {
  67         String timezone = TimeZone.getTimeZone(location)
  68                                   .getDisplayName(isSummerTime, style, ENGLISH);
  69         if (!timezone.equals(expected)) {
  70             System.err.println("wrong time zone string for location '" + location
  71                               +"': got '" + timezone + "', expected'" + expected + "'");
  72             return 1;
  73         }
  74 
  75         return 0;
  76     }
  77 }