< prev index next >

test/jdk/java/util/TimeZone/TransitionTest.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2002, 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.

@@ -22,28 +22,29 @@
   */
  
  /*
   * @test
   * @bug 4278609 4761696
-  * @library /java/text/testlib
   * @summary Make sure to handle DST transition ending at 0:00 January 1.
+  * @run junit TransitionTest
   */
  
  import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.GregorianCalendar;
  import java.util.Locale;
  import java.util.SimpleTimeZone;
  import java.util.TimeZone;
  
- public class TransitionTest extends IntlTest {
+ import org.junit.jupiter.api.Test;
  
-     public static void main(String[] args) throws Exception {
-         new TransitionTest().run(args);
-     }
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class TransitionTest {
  
+     @Test
      public void Test4278609() {
          SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
                                 /* DST start day: August, 1, 0:00 */
                                 Calendar.AUGUST, 1, 0, 0,
                                 /* DST end day: January, 1, 0:00 (wall-clock)*/

@@ -75,21 +76,22 @@
  
          if (offset != 0) {
              SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
                                                             Locale.US);
              format.setTimeZone(tz);
-             errln("Wrong DST transition: " + tz
+             fail("Wrong DST transition: " + tz
                    + "\na date just after DST = " + format.format(date)
                    + "\ngetOffset = " + offset);
          }
      }
  
      /*
       * 4761696: Rewrite SimpleTimeZone to support correct DST transitions
       *
       * Derived from JCK test cases some of which specify wrong day of week values.
       */
+     @Test
      public void Test4761696() {
          GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
  
          // test#1
          int rawOffset = -43200000;

@@ -119,11 +121,11 @@
          cal.set(y + 1, Calendar.JANUARY, 1);
          cal.set(cal.MILLISECOND, -saving);
          long endTime = cal.getTimeInMillis() + rawOffset;
          long expectedOffset = (localtime < endTime) ? rawOffset + saving : rawOffset;
          if (offset != expectedOffset) {
-             errln("test#1: wrong offset: got "+offset+", expected="+expectedOffset);
+             fail("test#1: wrong offset: got "+offset+", expected="+expectedOffset);
          }
  
          // test#2
          saving = 1;
          timeOfDay = 0;

@@ -148,11 +150,11 @@
          cal.set(y + 1, Calendar.JANUARY, 1);
          cal.set(cal.MILLISECOND, -saving);
          endTime = cal.getTimeInMillis() + rawOffset;
          expectedOffset = (localtime < endTime) ? rawOffset + saving : rawOffset;
          if (offset != expectedOffset) {
-             errln("Wrong offset: got "+offset+", expected="+expectedOffset);
+             fail("Wrong offset: got "+offset+", expected="+expectedOffset);
          }
  
          rawOffset = 43200000;
          saving = 1;
          timeOfDay = 3599998;

@@ -177,11 +179,11 @@
          cal.set(y + 1, Calendar.JANUARY, 1);
          cal.set(cal.MILLISECOND, 3600000-saving);
          endTime = cal.getTimeInMillis() + rawOffset;
          expectedOffset = (localtime < endTime) ? rawOffset + saving : rawOffset;
          if (offset != expectedOffset) {
-             errln("test#2: wrong offset: got "+offset+", expected="+expectedOffset);
+             fail("test#2: wrong offset: got "+offset+", expected="+expectedOffset);
          }
  
          // test#3
          rawOffset = -43200000;
          saving = 1800000;

@@ -207,11 +209,11 @@
          cal.set(y, Calendar.MARCH, 1);
          cal.set(cal.MILLISECOND, -saving);
          endTime = cal.getTimeInMillis() + rawOffset;
          expectedOffset = (localtime < endTime) ? rawOffset + saving : rawOffset;
          if (offset != expectedOffset) {
-             errln("test#3: wrong offset: got "+offset+", expected="+expectedOffset);
+             fail("test#3: wrong offset: got "+offset+", expected="+expectedOffset);
          }
  
          // test#4
          rawOffset = -43200000;
          saving = 1;

@@ -241,11 +243,11 @@
          cal.set(cal.DAY_OF_WEEK, 1);
          cal.set(cal.MILLISECOND, 3600000-saving);
          long startTime = cal.getTimeInMillis() + rawOffset;
          expectedOffset = (localtime >= startTime) ? rawOffset + saving : rawOffset;
          if (offset != expectedOffset) {
-             errln("test#4: wrong offset: got "+offset+", expected="+expectedOffset);
+             fail("test#4: wrong offset: got "+offset+", expected="+expectedOffset);
          }
  
          // test#5
          rawOffset = 0;
          saving = 3600000;

@@ -270,11 +272,11 @@
          cal.set(year, Calendar.OCTOBER, 10);
          cal.set(cal.MILLISECOND, 7200000-saving);
          endTime = cal.getTimeInMillis() + rawOffset;
          expectedOffset = (localtime < endTime) ? rawOffset + saving : rawOffset;
          if (offset != expectedOffset) {
-             errln("test#5: wrong offset: got "+offset+", expected="+expectedOffset);
+             fail("test#5: wrong offset: got "+offset+", expected="+expectedOffset);
          }
      }
  
      public static final long floorDivide(long n, long d) {
          return ((n >= 0) ?
< prev index next >