< prev index next >

test/jdk/java/util/Date/DateRegression.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 1998, 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,25 +22,26 @@
   */
  
  /*
   * @test
   * @bug 4023247 4027685 4032037 4072029 4073003 4118010 4120606 4133833 4136916 6274757 6314387
-  * @library /java/text/testlib
+  * @run junit DateRegression
   */
  
  import java.util.*;
  
- @SuppressWarnings("deprecation")
- public class DateRegression extends IntlTest {
+ import org.junit.jupiter.api.Test;
  
-     public static void main(String[] args) throws Exception {
-         new DateRegression().run(args);
-     }
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ @SuppressWarnings("deprecation")
+ public class DateRegression {
  
      /**
       * @bug 4023247
       */
+     @Test
      public void Test4023247() {
          Date d1 = new Date(0);
          Date d2 = new Date(0);
  
          d1.setYear(96);

@@ -56,50 +57,53 @@
          d2.setHours(0);
          d2.setMinutes(0);
          d2.setSeconds(0);
  
          if (d1.hashCode() != d2.hashCode())
-             errln("Fail: Date hashCode misbehaves");
+             fail("Fail: Date hashCode misbehaves");
      }
  
      /**
       * @bug 4027685
       */
+     @Test
      public void Test4027685() {
          // Should be 01/16/97 00:00:00
          Date nite = new Date("16-JAN-97 12:00 AM");
          // Should be 01/16/97 12:00:00
          Date noon = new Date("16-JAN-97 12:00 PM");
  
-         logln("Midnight = " + nite + ", Noon = " + noon);
+         System.out.println("Midnight = " + nite + ", Noon = " + noon);
          if (!nite.equals(new Date(97, Calendar.JANUARY, 16, 0, 0)) ||
              !noon.equals(new Date(97, Calendar.JANUARY, 16, 12, 0)))
-             errln("Fail: Nite/Noon confused");
+             fail("Fail: Nite/Noon confused");
      }
  
      /**
       * @bug 4032037
       */
+     @Test
      public void Test4032037() {
          Date ref = new Date(97, 1, 10);
          Date d = new Date(Date.parse("2/10/97"));
-         logln("Date.parse(2/10/97) => " + d);
-         if (!d.equals(ref)) errln("Fail: Want " + ref + " Got " + d);
+         System.out.println("Date.parse(2/10/97) => " + d);
+         if (!d.equals(ref)) fail("Fail: Want " + ref + " Got " + d);
          d = new Date(Date.parse("10 feb 1997"));
-         logln("Date.parse(10 feb 1997) => " + d);
-         if (!d.equals(ref)) errln("Fail: Want " + ref + " Got " + d);
+         System.out.println("Date.parse(10 feb 1997) => " + d);
+         if (!d.equals(ref)) fail("Fail: Want " + ref + " Got " + d);
          d = new Date("2/10/97");
-         logln("Date(2/10/97) => " + d);
-         if (!d.equals(ref)) errln("Fail: Want " + ref + " Got " + d);
+         System.out.println("Date(2/10/97) => " + d);
+         if (!d.equals(ref)) fail("Fail: Want " + ref + " Got " + d);
          d = new Date("10 feb 1997");
-         logln("Date(10 feb 1997) => " + d);
-         if (!d.equals(ref)) errln("Fail: Want " + ref + " Got " + d);
+         System.out.println("Date(10 feb 1997) => " + d);
+         if (!d.equals(ref)) fail("Fail: Want " + ref + " Got " + d);
      }
  
      /**
       * @bug 4072029
       */
+     @Test
      public void Test4072029() {
          TimeZone saveZone = TimeZone.getDefault();
  
          try {
              TimeZone.setDefault(TimeZone.getTimeZone("PST"));

@@ -108,134 +112,141 @@
              Date now2 = new Date(now.toString());
              String s2 = now2.toString(); // An hour's difference
  
              if (!s.equals(s2) ||
                  Math.abs(now.getTime() - now2.getTime()) > 60000 /*one min*/) {
-                 errln("Fail: Roundtrip toString/parse");
+                 fail("Fail: Roundtrip toString/parse");
              }
          }
          finally {
              TimeZone.setDefault(saveZone);
          }
      }
  
      /**
       * @bug 4073003
       */
+     @Test
      public void Test4073003() {
          Date d = new Date(Date.parse("01/02/1984"));
          if (!d.equals(new Date(84, 0, 2)))
-             errln("Fail: Want 1/2/1984 Got " + d);
+             fail("Fail: Want 1/2/1984 Got " + d);
          d = new Date(Date.parse("02/03/2012"));
          if (!d.equals(new Date(112, 1, 3)))
-             errln("Fail: Want 2/3/2012 Got " + d);
+             fail("Fail: Want 2/3/2012 Got " + d);
          d = new Date(Date.parse("03/04/15"));
          if (!d.equals(new Date(115, 2, 4)))
-             errln("Fail: Want 3/4/2015 Got " + d);
+             fail("Fail: Want 3/4/2015 Got " + d);
      }
  
      /**
       * @bug 4118010
       * Regress bug:
       * Feb. 2000 has 29 days, but Date(2000, 1, 29) returns March 01, 2000
       * NOTE: This turned out to be a user error (passing in 2000 instead
       * of 2000-1900 to the Date constructor).
       */
+     @Test
      public void Test4118010() {
          Date d=new java.util.Date(2000-1900, Calendar.FEBRUARY, 29);
          int m=d.getMonth();
          int date=d.getDate();
          if (m != Calendar.FEBRUARY ||
              date != 29)
-             errln("Fail: Want Feb 29, got " + d);
+             fail("Fail: Want Feb 29, got " + d);
      }
  
      /**
       * @bug 4120606
       * Date objects share state after cloning.
       */
+     @Test
      public void Test4120606() {
          Date d = new Date(98, Calendar.JUNE, 24);
          d.setMonth(Calendar.MAY);
          Date e = (Date)d.clone();
          d.setMonth(Calendar.FEBRUARY);
          if (e.getMonth() != Calendar.MAY) {
-             errln("Cloned Date objects share state");
+             fail("Cloned Date objects share state");
          }
      }
  
      /**
       * @bug 4133833
       * Date constructor crashes with parameters out of range, when it should
       * normalize.
       */
+     @Test
      public void Test4133833() {
          Date date = new java.util.Date(12,15,19);
          Date exp  = new Date(1913-1900, Calendar.APRIL, 19);
          if (!date.equals(exp))
-             errln("Fail: Want " + exp +
+             fail("Fail: Want " + exp +
                                  "; got " + date);
      }
  
      /**
       * @bug 4136916
       * Date.toString() throws exception in 1.2b4-E
       * CANNOT REPRODUCE this bug
       */
+     @Test
      public void Test4136916() {
          Date time = new Date();
-         logln(time.toString());
+         System.out.println(time.toString());
      }
  
      /**
       * @bug 6274757
       * Date getTime and toString interaction for some time values
       */
+     @Test
      public void Test6274757() {
          TimeZone savedTz = TimeZone.getDefault();
          try {
              // Use a time zone west of GMT.
              TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
              TimeZone jdkGMT = TimeZone.getTimeZone("GMT");
              Calendar jdkCal = Calendar.getInstance(jdkGMT);
              jdkCal.clear();
              jdkCal.set(1582, Calendar.OCTOBER, 15);
-             logln("JDK time: " + jdkCal.getTime().getTime() );
-             logln("JDK time (str): " + jdkCal.getTime() );
-             logln("Day of month: " + jdkCal.get(Calendar.DAY_OF_MONTH));
+             System.out.println("JDK time: " + jdkCal.getTime().getTime() );
+             System.out.println("JDK time (str): " + jdkCal.getTime() );
+             System.out.println("Day of month: " + jdkCal.get(Calendar.DAY_OF_MONTH));
              Date co = jdkCal.getTime();
-             logln("Change over (Oct 15 1582) = " + co + " (" +
+             System.out.println("Change over (Oct 15 1582) = " + co + " (" +
                    co.getTime() + ")");
              long a = jdkCal.getTime().getTime();
              Date c = jdkCal.getTime();
              c.toString();
              long b = c.getTime();
  
              if (a != b) {
-                 errln("ERROR: " + a + " != " + b);
+                 fail("ERROR: " + a + " != " + b);
              } else {
-                 logln(a + " = " + b);
+                 System.out.println(a + " = " + b);
              }
          } finally {
              TimeZone.setDefault(savedTz);
          }
      }
  
      /**
       * @bug 6314387
       * JCK6.0: api/java_util/Date/index.html#misc fails, mustang
       */
+     @Test
      public void Test6314387() {
          Date d = new Date(Long.MAX_VALUE);
          int y = d.getYear();
          if (y != 292277094) {
-             errln("yesr: got " + y + ", expected 292277094");
+             fail("yesr: got " + y + ", expected 292277094");
          }
          d = new Date(Long.MIN_VALUE);
          y = d.getYear();
          if (y != 292267155) {
-             errln("yesr: got " + y + ", expected 292267155");
+             fail("yesr: got " + y + ", expected 292267155");
          }
      }
  }
  
  //eof
< prev index next >