< prev index next >

test/jdk/java/text/Format/DateFormat/TimeZoneNameTest.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 23,19 ***
  
  /**
   * @test
   * @bug 4348864 4112924 4425386 4495052 4836940 4851113 8008577
   * @summary test time zone display names in en_US locale
!  * @library /java/text/testlib
-  * @run main/othervm -Djava.locale.providers=COMPAT,SPI TimeZoneNameTest
   */
  
  import java.util.*;
  import java.text.*;
  
! public class TimeZoneNameTest extends IntlTest
  {
      static final String[] data = {
          // Added to verify the fix for 4836940
          "N", "Antarctica/Rothera", "ROTT", "Rothera Time", "ROTT", "Rothera Time",
          "N", "Asia/Tehran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",
          "N", "Iran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",
--- 23,30 ---
  
  /**
   * @test
   * @bug 4348864 4112924 4425386 4495052 4836940 4851113 8008577
   * @summary test time zone display names in en_US locale
!  * @run junit/othervm -Djava.locale.providers=COMPAT,SPI TimeZoneNameTest
   */
  
  import java.util.*;
  import java.text.*;
  
! import org.junit.jupiter.api.Test;
+ import org.junit.jupiter.api.BeforeAll;
+ 
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class TimeZoneNameTest
  {
+ 
+     // Change JVM default Locale
+     @BeforeAll
+     static void initAll() {
+         Locale.setDefault(Locale.US);
+     }
+ 
      static final String[] data = {
          // Added to verify the fix for 4836940
          "N", "Antarctica/Rothera", "ROTT", "Rothera Time", "ROTT", "Rothera Time",
          "N", "Asia/Tehran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",
          "N", "Iran", "IRST", "Iran Standard Time", "IRDT", "Iran Daylight Time",

*** 92,21 ***
                               "ChST", "Chamorro Standard Time",
          "N", "Pacific/Saipan", "ChST", "Chamorro Standard Time",
                                 "ChST", "Chamorro Standard Time",
      };
  
!     public static void main(String[] args) throws Exception {
-         Locale reservedLocale = Locale.getDefault();
-         try {
-             Locale.setDefault(Locale.US);
-             new TimeZoneNameTest().run(args);
-         } finally {
-             // restore the reserved locale
-             Locale.setDefault(reservedLocale);
-         }
-     }
- 
      public void Test4112924() {
          SimpleDateFormat lfmt = new SimpleDateFormat("zzzz");
          SimpleDateFormat sfmt = new SimpleDateFormat("z");
  
          GregorianCalendar june = new GregorianCalendar(2000, Calendar.JUNE, 21);
--- 103,11 ---
                               "ChST", "Chamorro Standard Time",
          "N", "Pacific/Saipan", "ChST", "Chamorro Standard Time",
                                 "ChST", "Chamorro Standard Time",
      };
  
!     @Test
      public void Test4112924() {
          SimpleDateFormat lfmt = new SimpleDateFormat("zzzz");
          SimpleDateFormat sfmt = new SimpleDateFormat("z");
  
          GregorianCalendar june = new GregorianCalendar(2000, Calendar.JUNE, 21);

*** 127,26 ***
  
              TimeZone tz = TimeZone.getTimeZone(data[i++]);
              lfmt.setTimeZone(tz);
              sfmt.setTimeZone(tz);
  
!             logln(tz.getID() + ": " + sfmt.format(sol1.getTime()) + ", " + lfmt.format(sol1.getTime()));
!             logln(tz.getID() + ": " + sfmt.format(sol2.getTime()) + ", " + lfmt.format(sol2.getTime()));
              String s = sfmt.format(sol1.getTime());
              if (!data[i].equals(s)) {
!                 errln(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
              }
              s = lfmt.format(sol1.getTime());
              if (!data[++i].equals(s)) {
!                 errln(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
              }
              s = sfmt.format(sol2.getTime());
              if (!data[++i].equals(s)) {
!                 errln(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
              }
              s = lfmt.format(sol2.getTime());
              if (!data[++i].equals(s)) {
!                 errln(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
              }
          }
      }
  }
--- 128,26 ---
  
              TimeZone tz = TimeZone.getTimeZone(data[i++]);
              lfmt.setTimeZone(tz);
              sfmt.setTimeZone(tz);
  
!             System.out.println(tz.getID() + ": " + sfmt.format(sol1.getTime()) + ", " + lfmt.format(sol1.getTime()));
!             System.out.println(tz.getID() + ": " + sfmt.format(sol2.getTime()) + ", " + lfmt.format(sol2.getTime()));
              String s = sfmt.format(sol1.getTime());
              if (!data[i].equals(s)) {
!                 fail(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
              }
              s = lfmt.format(sol1.getTime());
              if (!data[++i].equals(s)) {
!                 fail(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
              }
              s = sfmt.format(sol2.getTime());
              if (!data[++i].equals(s)) {
!                 fail(tz.getID() + ": wrong short name: \"" + s + "\" (expected \"" + data[i] + "\")");
              }
              s = lfmt.format(sol2.getTime());
              if (!data[++i].equals(s)) {
!                 fail(tz.getID() + ": wrong long name: \"" + s + "\" (expected \"" + data[i] + "\")");
              }
          }
      }
  }
< prev index next >