< prev index next >

test/jdk/java/util/Calendar/CalendarTest.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 1997, 2022, 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) 1997, 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.

*** 25,11 ***
   * @test
   * @bug 4064654 4374886 4984320 4984574 4944795 8210142
   * @summary test for Calendar
   * @library /java/text/testlib
   * @modules java.base/java.util:+open
!  * @run main CalendarTest
   * @key randomness
   */
  
  import java.io.File;
  import java.io.FileInputStream;
--- 25,11 ---
   * @test
   * @bug 4064654 4374886 4984320 4984574 4944795 8210142
   * @summary test for Calendar
   * @library /java/text/testlib
   * @modules java.base/java.util:+open
!  * @run junit CalendarTest
   * @key randomness
   */
  
  import java.io.File;
  import java.io.FileInputStream;

*** 46,22 ***
  import java.util.SimpleTimeZone;
  import java.util.TimeZone;
  
  import static java.util.Calendar.*;
  
! public class CalendarTest extends IntlTest {
  
      static final int ONE_DAY = 24 * 60 * 60 * 1000;
      static final int EPOCH_JULIAN = 2440588;
  
-     public static void main(String argv[]) throws Exception {
-         new CalendarTest().run(argv);
-     }
- 
      /**
       * Test the behavior of the GregorianCalendar around the changeover.
       */
      public void TestGregorianChangeover() {
          TimeZone savedZone = TimeZone.getDefault();
          /*
            Changeover -7 days: 1582/9/28 dow=6
            Changeover -6 days: 1582/9/29 dow=7
--- 46,23 ---
  import java.util.SimpleTimeZone;
  import java.util.TimeZone;
  
  import static java.util.Calendar.*;
  
! import org.junit.jupiter.api.Test;
+ 
+ import static org.junit.jupiter.api.Assertions.fail;
+ 
+ public class CalendarTest {
  
      static final int ONE_DAY = 24 * 60 * 60 * 1000;
      static final int EPOCH_JULIAN = 2440588;
  
      /**
       * Test the behavior of the GregorianCalendar around the changeover.
       */
+     @Test
      public void TestGregorianChangeover() {
          TimeZone savedZone = TimeZone.getDefault();
          /*
            Changeover -7 days: 1582/9/28 dow=6
            Changeover -6 days: 1582/9/29 dow=7

*** 95,14 ***
                  int y = cal.get(YEAR);
                  int mon = cal.get(MONTH) + 1 - JANUARY;
                  int dom = cal.get(DATE);
                  int dow = cal.get(DAY_OF_WEEK);
  
!                 logln("Changeover " + (i >= 0 ? "+" : "") + i
                          + " days: " + y + "/" + mon + "/" + dom + " dow=" + dow);
                  if (y != 1582 || mon != MON[j] || dom != DOM[j] || dow != DOW[j]) {
!                     errln(" Fail: Above line is wrong");
                  }
              }
          } finally {
              TimeZone.setDefault(savedZone);
          }
--- 96,14 ---
                  int y = cal.get(YEAR);
                  int mon = cal.get(MONTH) + 1 - JANUARY;
                  int dom = cal.get(DATE);
                  int dow = cal.get(DAY_OF_WEEK);
  
!                 System.out.println("Changeover " + (i >= 0 ? "+" : "") + i
                          + " days: " + y + "/" + mon + "/" + dom + " dow=" + dow);
                  if (y != 1582 || mon != MON[j] || dom != DOM[j] || dow != DOW[j]) {
!                     fail(" Fail: Above line is wrong");
                  }
              }
          } finally {
              TimeZone.setDefault(savedZone);
          }

*** 112,10 ***
--- 113,11 ---
       * Test the mapping between millis and fields.  For the purposes
       * of this test, we don't care about timezones and week data
       * (first day of week, minimal days in first week).
       */
      @SuppressWarnings("deprecation")
+     @Test
      public void TestMapping() {
          TimeZone saveZone = TimeZone.getDefault();
          int[] DATA = {
              // Julian#   Year      Month    DOM   JULIAN:Year  Month,   DOM
              2440588,     1970,    JANUARY,   1,    1969,     DECEMBER,  19,

*** 158,13 ***
                          + " => " + calMillis
                          + " (" + ((float) delta / ONE_DAY) + " day delta) => "
                          + year2 + "-" + (month2 + 1 - JANUARY) + "-" + dom2;
                  if (delta != 0 || year != year2 || month != month2
                          || dom != dom2) {
!                     errln(s + " FAIL");
                  } else {
!                     logln(s);
                  }
  
                  // Test Julian computation
                  year = DATA[i + 4];
                  month = DATA[i + 5];
--- 160,13 ---
                          + " => " + calMillis
                          + " (" + ((float) delta / ONE_DAY) + " day delta) => "
                          + year2 + "-" + (month2 + 1 - JANUARY) + "-" + dom2;
                  if (delta != 0 || year != year2 || month != month2
                          || dom != dom2) {
!                     fail(s + " FAIL");
                  } else {
!                     System.out.println(s);
                  }
  
                  // Test Julian computation
                  year = DATA[i + 4];
                  month = DATA[i + 5];

*** 182,13 ***
                          + " => " + calMillis
                          + " (" + ((float) delta / ONE_DAY) + " day delta) => "
                          + year2 + "-" + (month2 + 1 - JANUARY) + "-" + dom2;
                  if (delta != 0 || year != year2 || month != month2
                          || dom != dom2) {
!                     errln(s + " FAIL");
                  } else {
!                     logln(s);
                  }
              }
  
              cal.setGregorianChange(new Date(1582 - 1900, OCTOBER, 15));
              auxMapping(cal, 1582, OCTOBER, 4);
--- 184,13 ---
                          + " => " + calMillis
                          + " (" + ((float) delta / ONE_DAY) + " day delta) => "
                          + year2 + "-" + (month2 + 1 - JANUARY) + "-" + dom2;
                  if (delta != 0 || year != year2 || month != month2
                          || dom != dom2) {
!                     fail(s + " FAIL");
                  } else {
!                     System.out.println(s);
                  }
              }
  
              cal.setGregorianChange(new Date(1582 - 1900, OCTOBER, 15));
              auxMapping(cal, 1582, OCTOBER, 4);

*** 210,20 ***
          cal.setTime(new Date(millis));
          int year2 = cal.get(YEAR);
          int month2 = cal.get(MONTH);
          int dom2 = cal.get(DAY_OF_MONTH);
          if (y != year2 || m != month2 || dom2 != d) {
!             errln("Round-trip failure: " + y + "-" + (m + 1) + "-" + d + " =>ms=> "
                      + year2 + "-" + (month2 + 1) + "-" + dom2);
          }
      }
  
      @SuppressWarnings("deprecation")
      public void TestGenericAPI() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             logln("Skipping this test because locale is " + locale);
              return;
          }
  
          String str;
          Date when = new Date(90, APRIL, 15);
--- 212,21 ---
          cal.setTime(new Date(millis));
          int year2 = cal.get(YEAR);
          int month2 = cal.get(MONTH);
          int dom2 = cal.get(DAY_OF_MONTH);
          if (y != year2 || m != month2 || dom2 != d) {
!             fail("Round-trip failure: " + y + "-" + (m + 1) + "-" + d + " =>ms=> "
                      + year2 + "-" + (month2 + 1) + "-" + dom2);
          }
      }
  
      @SuppressWarnings("deprecation")
+     @Test
      public void TestGenericAPI() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             System.out.println("Skipping this test because locale is " + locale);
              return;
          }
  
          String str;
          Date when = new Date(90, APRIL, 15);

*** 233,112 ***
  
          SimpleTimeZone zone = new SimpleTimeZone(tzoffset, tzid);
          Calendar cal = Calendar.getInstance((SimpleTimeZone) zone.clone());
  
          if (!zone.equals(cal.getTimeZone())) {
!             errln("FAIL: Calendar.getTimeZone failed");
          }
  
          Calendar cal2 = Calendar.getInstance(cal.getTimeZone());
  
          cal.setTime(when);
          cal2.setTime(when);
  
          if (!(cal.equals(cal2))) {
!             errln("FAIL: Calendar.operator== failed");
          }
          // if ((*cal != *cal2))  errln("FAIL: Calendar.operator!= failed");
          if (!cal.equals(cal2)
                  || cal.before(cal2)
                  || cal.after(cal2)) {
!             errln("FAIL: equals/before/after failed");
          }
  
          cal2.setTime(new Date(when.getTime() + 1000));
          if (cal.equals(cal2)
                  || cal2.before(cal)
                  || cal.after(cal2)) {
!             errln("FAIL: equals/before/after failed");
          }
  
          cal.roll(SECOND, true);
          if (!cal.equals(cal2)
                  || cal.before(cal2)
                  || cal.after(cal2)) {
!             errln("FAIL: equals/before/after failed");
          }
  
          // Roll back to January
          cal.roll(MONTH, 1 + DECEMBER - cal.get(MONTH));
          if (cal.equals(cal2)
                  || cal2.before(cal)
                  || cal.after(cal2)) {
!             errln("FAIL: equals/before/after failed");
          }
  
          // C++ only
          /* TimeZone z = cal.orphanTimeZone();
          if (z.getID(str) != tzid ||
          z.getRawOffset() != tzoffset)
!         errln("FAIL: orphanTimeZone failed");
          */
          for (int i = 0; i < 2; ++i) {
              boolean lenient = (i > 0);
              cal.setLenient(lenient);
              if (lenient != cal.isLenient()) {
!                 errln("FAIL: setLenient/isLenient failed");
              }
              // Later: Check for lenient behavior
          }
  
          int i;
          for (i = SUNDAY; i <= SATURDAY; ++i) {
              cal.setFirstDayOfWeek(i);
              if (cal.getFirstDayOfWeek() != i) {
!                 errln("FAIL: set/getFirstDayOfWeek failed");
              }
          }
  
          for (i = 0; i <= 7; ++i) {
              cal.setMinimalDaysInFirstWeek(i);
              if (cal.getMinimalDaysInFirstWeek() != i) {
!                 errln("FAIL: set/getFirstDayOfWeek failed");
              }
          }
  
          for (i = 0; i < FIELD_COUNT; ++i) {
              if (cal.getMinimum(i) != cal.getGreatestMinimum(i)) {
!                 errln("FAIL: getMinimum doesn't match getGreatestMinimum for field " + i);
              }
              if (cal.getLeastMaximum(i) > cal.getMaximum(i)) {
!                 errln("FAIL: getLeastMaximum larger than getMaximum for field " + i);
              }
              if (cal.getMinimum(i) >= cal.getMaximum(i)) {
!                 errln("FAIL: getMinimum not less than getMaximum for field " + i);
              }
          }
  
          cal.setTimeZone(TimeZone.getDefault());
          cal.clear();
          cal.set(1984, 5, 24);
          if (cal.getTime().getTime() != new Date(84, 5, 24).getTime()) {
!             errln("FAIL: Calendar.set(3 args) failed");
!             logln(" Got: " + cal.getTime() + "  Expected: " + new Date(84, 5, 24));
          }
  
          cal.clear();
          cal.set(1985, 3, 2, 11, 49);
          if (cal.getTime().getTime() != new Date(85, 3, 2, 11, 49).getTime()) {
!             errln("FAIL: Calendar.set(5 args) failed");
!             logln(" Got: " + cal.getTime() + "  Expected: " + new Date(85, 3, 2, 11, 49));
          }
  
          cal.clear();
          cal.set(1995, 9, 12, 1, 39, 55);
          if (cal.getTime().getTime() != new Date(95, 9, 12, 1, 39, 55).getTime()) {
!             errln("FAIL: Calendar.set(6 args) failed");
!             logln(" Got: " + cal.getTime() + "  Expected: " + new Date(95, 9, 12, 1, 39, 55));
          }
  
          cal.getTime();
          for (i = 0; i < FIELD_COUNT; ++i) {
              switch (i) {
--- 236,112 ---
  
          SimpleTimeZone zone = new SimpleTimeZone(tzoffset, tzid);
          Calendar cal = Calendar.getInstance((SimpleTimeZone) zone.clone());
  
          if (!zone.equals(cal.getTimeZone())) {
!             fail("FAIL: Calendar.getTimeZone failed");
          }
  
          Calendar cal2 = Calendar.getInstance(cal.getTimeZone());
  
          cal.setTime(when);
          cal2.setTime(when);
  
          if (!(cal.equals(cal2))) {
!             fail("FAIL: Calendar.operator== failed");
          }
          // if ((*cal != *cal2))  errln("FAIL: Calendar.operator!= failed");
          if (!cal.equals(cal2)
                  || cal.before(cal2)
                  || cal.after(cal2)) {
!             fail("FAIL: equals/before/after failed");
          }
  
          cal2.setTime(new Date(when.getTime() + 1000));
          if (cal.equals(cal2)
                  || cal2.before(cal)
                  || cal.after(cal2)) {
!             fail("FAIL: equals/before/after failed");
          }
  
          cal.roll(SECOND, true);
          if (!cal.equals(cal2)
                  || cal.before(cal2)
                  || cal.after(cal2)) {
!             fail("FAIL: equals/before/after failed");
          }
  
          // Roll back to January
          cal.roll(MONTH, 1 + DECEMBER - cal.get(MONTH));
          if (cal.equals(cal2)
                  || cal2.before(cal)
                  || cal.after(cal2)) {
!             fail("FAIL: equals/before/after failed");
          }
  
          // C++ only
          /* TimeZone z = cal.orphanTimeZone();
          if (z.getID(str) != tzid ||
          z.getRawOffset() != tzoffset)
!         fail("FAIL: orphanTimeZone failed");
          */
          for (int i = 0; i < 2; ++i) {
              boolean lenient = (i > 0);
              cal.setLenient(lenient);
              if (lenient != cal.isLenient()) {
!                 fail("FAIL: setLenient/isLenient failed");
              }
              // Later: Check for lenient behavior
          }
  
          int i;
          for (i = SUNDAY; i <= SATURDAY; ++i) {
              cal.setFirstDayOfWeek(i);
              if (cal.getFirstDayOfWeek() != i) {
!                 fail("FAIL: set/getFirstDayOfWeek failed");
              }
          }
  
          for (i = 0; i <= 7; ++i) {
              cal.setMinimalDaysInFirstWeek(i);
              if (cal.getMinimalDaysInFirstWeek() != i) {
!                 fail("FAIL: set/getFirstDayOfWeek failed");
              }
          }
  
          for (i = 0; i < FIELD_COUNT; ++i) {
              if (cal.getMinimum(i) != cal.getGreatestMinimum(i)) {
!                 fail("FAIL: getMinimum doesn't match getGreatestMinimum for field " + i);
              }
              if (cal.getLeastMaximum(i) > cal.getMaximum(i)) {
!                 fail("FAIL: getLeastMaximum larger than getMaximum for field " + i);
              }
              if (cal.getMinimum(i) >= cal.getMaximum(i)) {
!                 fail("FAIL: getMinimum not less than getMaximum for field " + i);
              }
          }
  
          cal.setTimeZone(TimeZone.getDefault());
          cal.clear();
          cal.set(1984, 5, 24);
          if (cal.getTime().getTime() != new Date(84, 5, 24).getTime()) {
!             fail("FAIL: Calendar.set(3 args) failed");
!             System.out.println(" Got: " + cal.getTime() + "  Expected: " + new Date(84, 5, 24));
          }
  
          cal.clear();
          cal.set(1985, 3, 2, 11, 49);
          if (cal.getTime().getTime() != new Date(85, 3, 2, 11, 49).getTime()) {
!             fail("FAIL: Calendar.set(5 args) failed");
!             System.out.println(" Got: " + cal.getTime() + "  Expected: " + new Date(85, 3, 2, 11, 49));
          }
  
          cal.clear();
          cal.set(1995, 9, 12, 1, 39, 55);
          if (cal.getTime().getTime() != new Date(95, 9, 12, 1, 39, 55).getTime()) {
!             fail("FAIL: Calendar.set(6 args) failed");
!             System.out.println(" Got: " + cal.getTime() + "  Expected: " + new Date(95, 9, 12, 1, 39, 55));
          }
  
          cal.getTime();
          for (i = 0; i < FIELD_COUNT; ++i) {
              switch (i) {

*** 347,30 ***
                  case DATE:
                  case HOUR_OF_DAY:
                  case MINUTE:
                  case SECOND:
                      if (!cal.isSet(i)) {
!                         errln("FAIL: !Calendar.isSet test failed: " + calendarFieldNames[i]);
                      }
                      break;
                  default:
                      if (cal.isSet(i)) {
!                         errln("FAIL: Calendar.isSet test failed: " + calendarFieldNames[i]);
                      }
              }
              cal.clear(i);
              if (cal.isSet(i)) {
!                 errln("FAIL: Calendar.clear/isSet failed");
              }
          }
  
          // delete cal;
          // delete cal2;
          Locale[] loc = Calendar.getAvailableLocales();
          long count = loc.length;
          if (count < 1 || loc == null) {
!             errln("FAIL: getAvailableLocales failed");
          } else {
              for (i = 0; i < count; ++i) {
                  cal = Calendar.getInstance(loc[i]);
                  // delete cal;
              }
--- 350,30 ---
                  case DATE:
                  case HOUR_OF_DAY:
                  case MINUTE:
                  case SECOND:
                      if (!cal.isSet(i)) {
!                         fail("FAIL: !Calendar.isSet test failed: " + calendarFieldNames[i]);
                      }
                      break;
                  default:
                      if (cal.isSet(i)) {
!                         fail("FAIL: Calendar.isSet test failed: " + calendarFieldNames[i]);
                      }
              }
              cal.clear(i);
              if (cal.isSet(i)) {
!                 fail("FAIL: Calendar.clear/isSet failed");
              }
          }
  
          // delete cal;
          // delete cal2;
          Locale[] loc = Calendar.getAvailableLocales();
          long count = loc.length;
          if (count < 1 || loc == null) {
!             fail("FAIL: getAvailableLocales failed");
          } else {
              for (i = 0; i < count; ++i) {
                  cal = Calendar.getInstance(loc[i]);
                  // delete cal;
              }

*** 397,17 ***
          gc = new GregorianCalendar(zone);
          // delete gc;
  
          gc = new GregorianCalendar(1998, 10, 14, 21, 43);
          if (gc.getTime().getTime() != new Date(98, 10, 14, 21, 43).getTime()) {
!             errln("FAIL: new GregorianCalendar(ymdhm) failed");
          }
          // delete gc;
  
          gc = new GregorianCalendar(1998, 10, 14, 21, 43, 55);
          if (gc.getTime().getTime() != new Date(98, 10, 14, 21, 43, 55).getTime()) {
!             errln("FAIL: new GregorianCalendar(ymdhms) failed");
          }
  
          // C++ only:
          // GregorianCalendar gc2 = new GregorianCalendar(Locale.ENGLISH);
          // gc2 = gc;
--- 400,17 ---
          gc = new GregorianCalendar(zone);
          // delete gc;
  
          gc = new GregorianCalendar(1998, 10, 14, 21, 43);
          if (gc.getTime().getTime() != new Date(98, 10, 14, 21, 43).getTime()) {
!             fail("FAIL: new GregorianCalendar(ymdhm) failed");
          }
          // delete gc;
  
          gc = new GregorianCalendar(1998, 10, 14, 21, 43, 55);
          if (gc.getTime().getTime() != new Date(98, 10, 14, 21, 43, 55).getTime()) {
!             fail("FAIL: new GregorianCalendar(ymdhms) failed");
          }
  
          // C++ only:
          // GregorianCalendar gc2 = new GregorianCalendar(Locale.ENGLISH);
          // gc2 = gc;

*** 415,10 ***
--- 418,11 ---
          // delete gc;
          // delete z;
      }
  
      // Verify Roger Webster's bug
+     @Test
      public void TestRog() {
          GregorianCalendar gc = new GregorianCalendar();
  
          int year = 1997, month = APRIL, date = 1;
          gc.set(year, month, date); // April 1, 1997

*** 430,16 ***
  
          for (int i = 0; i < 9; i++, gc.add(DATE, 1)) {
              if (gc.get(YEAR) != year
                      || gc.get(MONTH) != month
                      || gc.get(DATE) != (date + i)) {
!                 errln("FAIL: Date " + gc.getTime() + " wrong");
              }
          }
      }
  
      // Verify DAY_OF_WEEK
      public void TestDOW943() {
          dowTest(false);
          dowTest(true);
      }
  
--- 434,17 ---
  
          for (int i = 0; i < 9; i++, gc.add(DATE, 1)) {
              if (gc.get(YEAR) != year
                      || gc.get(MONTH) != month
                      || gc.get(DATE) != (date + i)) {
!                 fail("FAIL: Date " + gc.getTime() + " wrong");
              }
          }
      }
  
      // Verify DAY_OF_WEEK
+     @Test
      public void TestDOW943() {
          dowTest(false);
          dowTest(true);
      }
  

*** 451,54 ***
          cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996
          int dow = cal.get(DAY_OF_WEEK);
          int min = cal.getMinimum(DAY_OF_WEEK);
          int max = cal.getMaximum(DAY_OF_WEEK);
          if (dow < min || dow > max) {
!             errln("FAIL: Day of week " + dow + " out of range");
          }
          if (dow != SUNDAY) {
!             errln("FAIL2: Day of week should be SUNDAY; is " + dow + ": " + cal.getTime());
          }
          if (min != SUNDAY || max != SATURDAY) {
!             errln("FAIL: Min/max bad");
          }
      }
  
      // Verify that the clone method produces distinct objects with no
      // unintentionally shared fields.
      public void TestClonesUnique908() {
          Calendar c = Calendar.getInstance();
          Calendar d = (Calendar) c.clone();
          c.set(MILLISECOND, 123);
          d.set(MILLISECOND, 456);
          if (c.get(MILLISECOND) != 123
                  || d.get(MILLISECOND) != 456) {
!             errln("FAIL: Clones share fields");
          }
      }
  
      // Verify effect of Gregorian cutoff value
      @SuppressWarnings("deprecation")
      public void TestGregorianChange768() {
          boolean b;
          GregorianCalendar c = new GregorianCalendar();
!         logln("With cutoff " + c.getGregorianChange());
!         logln(" isLeapYear(1800) = " + (b = c.isLeapYear(1800)));
!         logln(" (should be FALSE)");
          if (b != false) {
!             errln("FAIL");
          }
          c.setGregorianChange(new Date(0, 0, 1)); // Jan 1 1900
!         logln("With cutoff " + c.getGregorianChange());
!         logln(" isLeapYear(1800) = " + (b = c.isLeapYear(1800)));
!         logln(" (should be TRUE)");
          if (b != true) {
!             errln("FAIL");
          }
      }
  
      // Test the correct behavior of the disambiguation algorithm.
      public void TestDisambiguation765() throws Exception {
          Locale savedLocale = Locale.getDefault();
          try {
              Locale.setDefault(Locale.US);
              Calendar c = Calendar.getInstance();
--- 456,57 ---
          cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996
          int dow = cal.get(DAY_OF_WEEK);
          int min = cal.getMinimum(DAY_OF_WEEK);
          int max = cal.getMaximum(DAY_OF_WEEK);
          if (dow < min || dow > max) {
!             fail("FAIL: Day of week " + dow + " out of range");
          }
          if (dow != SUNDAY) {
!             fail("FAIL2: Day of week should be SUNDAY; is " + dow + ": " + cal.getTime());
          }
          if (min != SUNDAY || max != SATURDAY) {
!             fail("FAIL: Min/max bad");
          }
      }
  
      // Verify that the clone method produces distinct objects with no
      // unintentionally shared fields.
+     @Test
      public void TestClonesUnique908() {
          Calendar c = Calendar.getInstance();
          Calendar d = (Calendar) c.clone();
          c.set(MILLISECOND, 123);
          d.set(MILLISECOND, 456);
          if (c.get(MILLISECOND) != 123
                  || d.get(MILLISECOND) != 456) {
!             fail("FAIL: Clones share fields");
          }
      }
  
      // Verify effect of Gregorian cutoff value
      @SuppressWarnings("deprecation")
+     @Test
      public void TestGregorianChange768() {
          boolean b;
          GregorianCalendar c = new GregorianCalendar();
!         System.out.println("With cutoff " + c.getGregorianChange());
!         System.out.println(" isLeapYear(1800) = " + (b = c.isLeapYear(1800)));
!         System.out.println(" (should be FALSE)");
          if (b != false) {
!             fail("FAIL");
          }
          c.setGregorianChange(new Date(0, 0, 1)); // Jan 1 1900
!         System.out.println("With cutoff " + c.getGregorianChange());
!         System.out.println(" isLeapYear(1800) = " + (b = c.isLeapYear(1800)));
!         System.out.println(" (should be TRUE)");
          if (b != true) {
!             fail("FAIL");
          }
      }
  
      // Test the correct behavior of the disambiguation algorithm.
+     @Test
      public void TestDisambiguation765() throws Exception {
          Locale savedLocale = Locale.getDefault();
          try {
              Locale.setDefault(Locale.US);
              Calendar c = Calendar.getInstance();

*** 560,11 ***
                  c.set(DAY_OF_WEEK, TUESDAY);
                  c.set(MONTH, JUNE);
                  c.set(WEEK_OF_MONTH, 1);
                  verify765("1997 Tuesday in week 0 of June = ", c, 1997, JUNE, 3);
              } catch (IllegalArgumentException ex) {
!                 errln("FAIL: Exception seen: " + ex.getMessage());
                  // ex.printStackTrace(log);
              }
  
              c.clear();
              c.set(YEAR, 1997);
--- 568,11 ---
                  c.set(DAY_OF_WEEK, TUESDAY);
                  c.set(MONTH, JUNE);
                  c.set(WEEK_OF_MONTH, 1);
                  verify765("1997 Tuesday in week 0 of June = ", c, 1997, JUNE, 3);
              } catch (IllegalArgumentException ex) {
!                 fail("FAIL: Exception seen: " + ex.getMessage());
                  // ex.printStackTrace(log);
              }
  
              c.clear();
              c.set(YEAR, 1997);

*** 594,32 ***
  
      void verify765(String msg, Calendar c, int year, int month, int day) {
          if (c.get(YEAR) == year
                  && c.get(MONTH) == month
                  && c.get(DATE) == day) {
!             logln("PASS: " + msg + c.getTime());
          } else {
!             errln("FAIL: " + msg + c.getTime()
                      + "; expected "
                      + year + "/" + (month + 1) + "/" + day);
          }
      }
  
      // Called when e expected to be non-null
      void verify765(String msg, IllegalArgumentException e) {
          if (e == null) {
!             errln("FAIL: No IllegalArgumentException for " + msg);
          } else {
!             logln("PASS: " + msg + "IllegalArgument as expected");
          }
      }
  
      // Test the behavior of GMT vs. local time
      public void TestGMTvsLocal4064654() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             logln("Skipping this test because locale is " + locale);
              return;
          }
  
          // Sample output 1:
          // % /usr/local/java/jdk1.1.3/solaris/bin/java test 1997 1 1 12 0 0
--- 602,33 ---
  
      void verify765(String msg, Calendar c, int year, int month, int day) {
          if (c.get(YEAR) == year
                  && c.get(MONTH) == month
                  && c.get(DATE) == day) {
!             System.out.println("PASS: " + msg + c.getTime());
          } else {
!             fail("FAIL: " + msg + c.getTime()
                      + "; expected "
                      + year + "/" + (month + 1) + "/" + day);
          }
      }
  
      // Called when e expected to be non-null
      void verify765(String msg, IllegalArgumentException e) {
          if (e == null) {
!             fail("FAIL: No IllegalArgumentException for " + msg);
          } else {
!             System.out.println("PASS: " + msg + "IllegalArgument as expected");
          }
      }
  
      // Test the behavior of GMT vs. local time
+     @Test
      public void TestGMTvsLocal4064654() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             System.out.println("Skipping this test because locale is " + locale);
              return;
          }
  
          // Sample output 1:
          // % /usr/local/java/jdk1.1.3/solaris/bin/java test 1997 1 1 12 0 0

*** 643,11 ***
          gmtcal.setTimeZone(TimeZone.getTimeZone("Africa/Casablanca"));
          gmtcal.set(yr, mo - 1, dt, hr, mn, sc);
          gmtcal.set(MILLISECOND, 0);
  
          date = gmtcal.getTime();
!         logln("date = " + date);
  
          Calendar cal = Calendar.getInstance();
          cal.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
          cal.setTime(date);
  
--- 652,11 ---
          gmtcal.setTimeZone(TimeZone.getTimeZone("Africa/Casablanca"));
          gmtcal.set(yr, mo - 1, dt, hr, mn, sc);
          gmtcal.set(MILLISECOND, 0);
  
          date = gmtcal.getTime();
!         System.out.println("date = " + date);
  
          Calendar cal = Calendar.getInstance();
          cal.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
          cal.setTime(date);
  

*** 656,28 ***
                  cal.get(MONTH),
                  cal.get(DATE),
                  cal.get(DAY_OF_WEEK),
                  cal.get(MILLISECOND));
  
!         logln("offset for " + date + "= " + (offset / 1000 / 60 / 60.0) + "hr");
  
          int utc = ((cal.get(HOUR_OF_DAY) * 60
                  + cal.get(MINUTE)) * 60
                  + cal.get(SECOND)) * 1000
                  + cal.get(MILLISECOND) - offset;
  
          int expected = ((hr * 60 + mn) * 60 + sc) * 1000;
  
          if (utc != expected) {
!             errln("FAIL: Discrepancy of "
                      + (utc - expected) + " millis = "
                      + ((utc - expected) / 1000 / 60 / 60.0) + " hr");
          }
      }
  
      // Verify that add and set work regardless of the order in which
      // they are called.
      public void TestAddSetOrder621() {
          @SuppressWarnings("deprecation")
          Date d = new Date(97, 4, 14, 13, 23, 45);
  
          Calendar cal = Calendar.getInstance();
--- 665,29 ---
                  cal.get(MONTH),
                  cal.get(DATE),
                  cal.get(DAY_OF_WEEK),
                  cal.get(MILLISECOND));
  
!         System.out.println("offset for " + date + "= " + (offset / 1000 / 60 / 60.0) + "hr");
  
          int utc = ((cal.get(HOUR_OF_DAY) * 60
                  + cal.get(MINUTE)) * 60
                  + cal.get(SECOND)) * 1000
                  + cal.get(MILLISECOND) - offset;
  
          int expected = ((hr * 60 + mn) * 60 + sc) * 1000;
  
          if (utc != expected) {
!             fail("FAIL: Discrepancy of "
                      + (utc - expected) + " millis = "
                      + ((utc - expected) / 1000 / 60 / 60.0) + " hr");
          }
      }
  
      // Verify that add and set work regardless of the order in which
      // they are called.
+     @Test
      public void TestAddSetOrder621() {
          @SuppressWarnings("deprecation")
          Date d = new Date(97, 4, 14, 13, 23, 45);
  
          Calendar cal = Calendar.getInstance();

*** 697,17 ***
          cal.add(DATE, -5);
          // ma feb 03 13:11:06 GMT+00:00 1997
          String s2 = cal.getTime().toString();
  
          if (s.equals(s2)) {
!             logln("Pass: " + s + " == " + s2);
          } else {
!             errln("FAIL: " + s + " != " + s2);
          }
      }
  
      // Verify that add works.
      public void TestAdd520() {
          int y = 1997, m = FEBRUARY, d = 1;
          GregorianCalendar temp = new GregorianCalendar(y, m, d);
          check520(temp, y, m, d);
  
--- 707,18 ---
          cal.add(DATE, -5);
          // ma feb 03 13:11:06 GMT+00:00 1997
          String s2 = cal.getTime().toString();
  
          if (s.equals(s2)) {
!             System.out.println("Pass: " + s + " == " + s2);
          } else {
!             fail("FAIL: " + s + " != " + s2);
          }
      }
  
      // Verify that add works.
+     @Test
      public void TestAdd520() {
          int y = 1997, m = FEBRUARY, d = 1;
          GregorianCalendar temp = new GregorianCalendar(y, m, d);
          check520(temp, y, m, d);
  

*** 735,23 ***
  
      void check520(Calendar c, int y, int m, int d) {
          if (c.get(YEAR) != y
                  || c.get(MONTH) != m
                  || c.get(DATE) != d) {
!             errln("FAILURE: Expected YEAR/MONTH/DATE of "
                      + y + "/" + (m + 1) + "/" + d
                      + "; got "
                      + c.get(YEAR) + "/"
                      + (c.get(MONTH) + 1) + "/"
                      + c.get(DATE));
          } else {
!             logln("Confirmed: "
                      + y + "/" + (m + 1) + "/" + d);
          }
      }
  
      // Verify that setting fields works.  This test fails when an exception is thrown.
      public void TestFieldSet4781() {
          try {
              GregorianCalendar g = new GregorianCalendar();
              GregorianCalendar g2 = new GregorianCalendar();
              // At this point UTC value is set, various fields are not.
--- 746,24 ---
  
      void check520(Calendar c, int y, int m, int d) {
          if (c.get(YEAR) != y
                  || c.get(MONTH) != m
                  || c.get(DATE) != d) {
!             fail("FAILURE: Expected YEAR/MONTH/DATE of "
                      + y + "/" + (m + 1) + "/" + d
                      + "; got "
                      + c.get(YEAR) + "/"
                      + (c.get(MONTH) + 1) + "/"
                      + c.get(DATE));
          } else {
!             System.out.println("Confirmed: "
                      + y + "/" + (m + 1) + "/" + d);
          }
      }
  
      // Verify that setting fields works.  This test fails when an exception is thrown.
+     @Test
      public void TestFieldSet4781() {
          try {
              GregorianCalendar g = new GregorianCalendar();
              GregorianCalendar g2 = new GregorianCalendar();
              // At this point UTC value is set, various fields are not.

*** 761,20 ***
              g2.set(SECOND, 0);
              // At this point the object thinks UTC is NOT set, but fields are set.
              // The following line will result in IllegalArgumentException because
              // it thinks the YEAR is set and it is NOT.
              if (g2.equals(g)) {
!                 logln("Same");
              } else {
!                 logln("Different");
              }
          } catch (IllegalArgumentException e) {
!             errln("Unexpected exception seen: " + e);
          }
      }
  
      // Test serialization of a Calendar object
      public void TestSerialize337() {
          Calendar cal = Calendar.getInstance();
  
          boolean ok = false;
  
--- 773,21 ---
              g2.set(SECOND, 0);
              // At this point the object thinks UTC is NOT set, but fields are set.
              // The following line will result in IllegalArgumentException because
              // it thinks the YEAR is set and it is NOT.
              if (g2.equals(g)) {
!                 System.out.println("Same");
              } else {
!                 System.out.println("Different");
              }
          } catch (IllegalArgumentException e) {
!             fail("Unexpected exception seen: " + e);
          }
      }
  
      // Test serialization of a Calendar object
+     @Test
      public void TestSerialize337() {
          Calendar cal = Calendar.getInstance();
  
          boolean ok = false;
  

*** 798,57 ***
                      && cal.equals(c);
  
              File fl = new File(FILENAME);
              fl.delete();
          } catch (IOException e) {
!             errln("FAIL: Exception received:");
              // e.printStackTrace(log);
          } catch (ClassNotFoundException e) {
!             errln("FAIL: Exception received:");
              // e.printStackTrace(log);
          }
  
          if (!ok) {
!             errln("Serialization of Calendar object failed.");
          }
      }
      static final String PREFIX = "abc";
      static final String POSTFIX = "def";
      static final String FILENAME = "tmp337.bin";
  
      // Try to zero out the seconds field
      public void TestSecondsZero121() {
          Calendar cal = new GregorianCalendar();
          // Initialize with current date/time
          cal.setTime(new Date());
          // Round down to minute
          cal.set(SECOND, 0);
          Date d = cal.getTime();
          String s = d.toString();
          if (s.indexOf(":00 ") < 0) {
!             errln("Expected to see :00 in " + s);
          }
      }
  
      // Try various sequences of add, set, and get method calls.
      public void TestAddSetGet0610() {
          //
          // Error case 1:
          // - Upon initialization calendar fields, millis = System.currentTime
          // - After set is called fields are initialized, time is not
          // - Addition uses millis which are still *now*
          //
          {
              Calendar calendar = new GregorianCalendar();
              calendar.set(1993, JANUARY, 4);
!             logln("1A) " + value(calendar));
              calendar.add(DATE, 1);
              String v = value(calendar);
!             logln("1B) " + v);
!             logln("--) 1993/0/5");
              if (!v.equals(EXPECTED_0610)) {
!                 errln("Expected " + EXPECTED_0610
                          + "; saw " + v);
              }
          }
  
          //
--- 811,59 ---
                      && cal.equals(c);
  
              File fl = new File(FILENAME);
              fl.delete();
          } catch (IOException e) {
!             fail("FAIL: Exception received:");
              // e.printStackTrace(log);
          } catch (ClassNotFoundException e) {
!             fail("FAIL: Exception received:");
              // e.printStackTrace(log);
          }
  
          if (!ok) {
!             fail("Serialization of Calendar object failed.");
          }
      }
      static final String PREFIX = "abc";
      static final String POSTFIX = "def";
      static final String FILENAME = "tmp337.bin";
  
      // Try to zero out the seconds field
+     @Test
      public void TestSecondsZero121() {
          Calendar cal = new GregorianCalendar();
          // Initialize with current date/time
          cal.setTime(new Date());
          // Round down to minute
          cal.set(SECOND, 0);
          Date d = cal.getTime();
          String s = d.toString();
          if (s.indexOf(":00 ") < 0) {
!             fail("Expected to see :00 in " + s);
          }
      }
  
      // Try various sequences of add, set, and get method calls.
+     @Test
      public void TestAddSetGet0610() {
          //
          // Error case 1:
          // - Upon initialization calendar fields, millis = System.currentTime
          // - After set is called fields are initialized, time is not
          // - Addition uses millis which are still *now*
          //
          {
              Calendar calendar = new GregorianCalendar();
              calendar.set(1993, JANUARY, 4);
!             System.out.println("1A) " + value(calendar));
              calendar.add(DATE, 1);
              String v = value(calendar);
!             System.out.println("1B) " + v);
!             System.out.println("--) 1993/0/5");
              if (!v.equals(EXPECTED_0610)) {
!                 fail("Expected " + EXPECTED_0610
                          + "; saw " + v);
              }
          }
  
          //

*** 856,17 ***
          // - Upon initialization calendar fields set, millis = 0
          // - Addition uses millis which are still 1970, 0, 1
          //
          {
              Calendar calendar = new GregorianCalendar(1993, JANUARY, 4);
!             logln("2A) " + value(calendar));
              calendar.add(DATE, 1);
              String v = value(calendar);
!             logln("2B) " + v);
!             logln("--) 1993/0/5");
              if (!v.equals(EXPECTED_0610)) {
!                 errln("Expected " + EXPECTED_0610
                          + "; saw " + v);
              }
          }
  
          //
--- 871,17 ---
          // - Upon initialization calendar fields set, millis = 0
          // - Addition uses millis which are still 1970, 0, 1
          //
          {
              Calendar calendar = new GregorianCalendar(1993, JANUARY, 4);
!             System.out.println("2A) " + value(calendar));
              calendar.add(DATE, 1);
              String v = value(calendar);
!             System.out.println("2B) " + v);
!             System.out.println("--) 1993/0/5");
              if (!v.equals(EXPECTED_0610)) {
!                 fail("Expected " + EXPECTED_0610
                          + "; saw " + v);
              }
          }
  
          //

*** 875,18 ***
          // - getTime( ) is called which forces the millis to be set
          // - Addition uses millis which are correct
          //
          {
              Calendar calendar = new GregorianCalendar(1993, JANUARY, 4);
!             logln("3A) " + value(calendar));
              calendar.getTime();
              calendar.add(DATE, 1);
              String v = value(calendar);
!             logln("3B) " + v);
!             logln("--) 1993/0/5");
              if (!v.equals(EXPECTED_0610)) {
!                 errln("Expected " + EXPECTED_0610
                          + "; saw " + v);
              }
          }
      }
      static String value(Calendar calendar) {
--- 890,18 ---
          // - getTime( ) is called which forces the millis to be set
          // - Addition uses millis which are correct
          //
          {
              Calendar calendar = new GregorianCalendar(1993, JANUARY, 4);
!             System.out.println("3A) " + value(calendar));
              calendar.getTime();
              calendar.add(DATE, 1);
              String v = value(calendar);
!             System.out.println("3B) " + v);
!             System.out.println("--) 1993/0/5");
              if (!v.equals(EXPECTED_0610)) {
!                 fail("Expected " + EXPECTED_0610
                          + "; saw " + v);
              }
          }
      }
      static String value(Calendar calendar) {

*** 895,10 ***
--- 910,11 ---
                  + calendar.get(DATE));
      }
      static String EXPECTED_0610 = "1993/0/5";
  
      // Test that certain fields on a certain date are as expected.
+     @Test
      public void TestFields060() {
          int year = 1997;
          int month = OCTOBER;  //october
          int dDate = 22;   //DAYOFWEEK should return 3 for Wednesday
          GregorianCalendar calendar = null;

*** 906,11 ***
          calendar = new GregorianCalendar(year, month, dDate);
          for (int i = 0; i < EXPECTED_FIELDS.length;) {
              int field = EXPECTED_FIELDS[i++];
              int expected = EXPECTED_FIELDS[i++];
              if (calendar.get(field) != expected) {
!                 errln("Expected field " + field + " to have value " + expected
                          + "; received " + calendar.get(field) + " instead");
              }
          }
      }
      static int[] EXPECTED_FIELDS = {
--- 922,11 ---
          calendar = new GregorianCalendar(year, month, dDate);
          for (int i = 0; i < EXPECTED_FIELDS.length;) {
              int field = EXPECTED_FIELDS[i++];
              int expected = EXPECTED_FIELDS[i++];
              if (calendar.get(field) != expected) {
!                 fail("Expected field " + field + " to have value " + expected
                          + "; received " + calendar.get(field) + " instead");
              }
          }
      }
      static int[] EXPECTED_FIELDS = {

*** 940,10 ***
--- 956,11 ---
          /* 15 */ "ZONE_OFFSET",
          /* 16 */ "DST_OFFSET"};
  
      // Verify that the fields are as expected (mostly zero) at the epoch start.
      // Note that we adjust for the default timezone to get most things to zero.
+     @Test
      public void TestEpochStartFields() {
          String[][] lt = {
              {"en", "US", "US/Pacific"},        /* First day = 1, Minimum day = 1 */
              {"en", "US", "America/Anchorage"}, /* First day = 1, Minimum day = 1 */
              {"en", "TO", "Pacific/Tongatapu"}, /* First day = 1, Minimum day = 1 */

*** 986,18 ***
                  c.setTime(d);
  
                  boolean err = false;
                  for (int i = 0; i < calendarFieldNames.length; ++i) {
                      if ((val = c.get(i)) != EPOCH_FIELDS[i]) {
!                         errln("Wrong value: " + val
                                  + " for field(" + calendarFieldNames[i]
                                  + "), expected: " + EPOCH_FIELDS[i]);
                          err = true;
                      }
                  }
                  if (err) {
!                     errln("Failed: \n\tDate=" + d + "\n\tTimeZone=" + z
                              + "\n\tLocale=" + l + "\n\tCalendar=" + c);
                  }
              }
          } finally {
              Locale.setDefault(savedLocale);
--- 1003,18 ---
                  c.setTime(d);
  
                  boolean err = false;
                  for (int i = 0; i < calendarFieldNames.length; ++i) {
                      if ((val = c.get(i)) != EPOCH_FIELDS[i]) {
!                         fail("Wrong value: " + val
                                  + " for field(" + calendarFieldNames[i]
                                  + "), expected: " + EPOCH_FIELDS[i]);
                          err = true;
                      }
                  }
                  if (err) {
!                     fail("Failed: \n\tDate=" + d + "\n\tTimeZone=" + z
                              + "\n\tLocale=" + l + "\n\tCalendar=" + c);
                  }
              }
          } finally {
              Locale.setDefault(savedLocale);

*** 1005,10 ***
--- 1022,11 ---
          }
      }
  
      // Verify that as you add days to the calendar (e.g., 24 day periods),
      // the day of the week shifts in the expected pattern.
+     @Test
      public void TestDOWProgression() {
          Calendar cal
                  = new GregorianCalendar(1972, OCTOBER, 26);
          marchByDelta(cal, 24); // Last parameter must be != 0 modulo 7
      }

*** 1018,80 ***
          Calendar cur = (Calendar) cal.clone();
          int initialDOW = cur.get(DAY_OF_WEEK);
          int DOW, newDOW = initialDOW;
          do {
              DOW = newDOW;
!             logln("DOW = " + DOW + "  " + cur.getTime());
  
              cur.add(DAY_OF_WEEK, delta);
              newDOW = cur.get(DAY_OF_WEEK);
              int expectedDOW = 1 + (DOW + delta - 1) % 7;
              if (newDOW != expectedDOW) {
!                 errln("Day of week should be " + expectedDOW
                          + " instead of " + newDOW + " on " + cur.getTime());
                  return;
              }
          } while (newDOW != initialDOW);
      }
  
      public void TestActualMinMax() {
          Calendar cal = new GregorianCalendar(1967, MARCH, 10);
          cal.setFirstDayOfWeek(SUNDAY);
          cal.setMinimalDaysInFirstWeek(3);
  
          if (cal.getActualMinimum(DAY_OF_MONTH) != 1) {
!             errln("Actual minimum date for 3/10/1967 should have been 1; got "
                      + cal.getActualMinimum(DAY_OF_MONTH));
          }
          if (cal.getActualMaximum(DAY_OF_MONTH) != 31) {
!             errln("Actual maximum date for 3/10/1967 should have been 31; got "
                      + cal.getActualMaximum(DAY_OF_MONTH));
          }
  
          cal.set(MONTH, FEBRUARY);
          if (cal.getActualMaximum(DAY_OF_MONTH) != 28) {
!             errln("Actual maximum date for 2/10/1967 should have been 28; got "
                      + cal.getActualMaximum(DAY_OF_MONTH));
          }
          if (cal.getActualMaximum(DAY_OF_YEAR) != 365) {
!             errln("Number of days in 1967 should have been 365; got "
                      + cal.getActualMaximum(DAY_OF_YEAR));
          }
  
          cal.set(YEAR, 1968);
          if (cal.getActualMaximum(DAY_OF_MONTH) != 29) {
!             errln("Actual maximum date for 2/10/1968 should have been 29; got "
                      + cal.getActualMaximum(DAY_OF_MONTH));
          }
          if (cal.getActualMaximum(DAY_OF_YEAR) != 366) {
!             errln("Number of days in 1968 should have been 366; got "
                      + cal.getActualMaximum(DAY_OF_YEAR));
          }
          // Using week settings of SUNDAY/3 (see above)
          if (cal.getActualMaximum(WEEK_OF_YEAR) != 52) {
!             errln("Number of weeks in 1968 should have been 52; got "
                      + cal.getActualMaximum(WEEK_OF_YEAR));
          }
  
          cal.set(YEAR, 1976);
          // Using week settings of SUNDAY/3 (see above)
          if (cal.getActualMaximum(WEEK_OF_YEAR) != 53) {
!             errln("Number of weeks in 1976 should have been 53; got "
                      + cal.getActualMaximum(WEEK_OF_YEAR));
          }
      }
  
      public void TestRoll() {
          Calendar cal = new GregorianCalendar(1997, JANUARY, 31);
  
          int[] dayValues = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31};
  
          for (int i = 0; i < dayValues.length; i++) {
              Calendar cal2 = (Calendar) cal.clone();
              cal2.roll(MONTH, i);
              if (cal2.get(DAY_OF_MONTH) != dayValues[i]) {
!                 errln("Rolling the month in 1/31/1997 up by " + i + " should have yielded "
                          + ((i + 1) % 12) + "/" + dayValues[i] + "/1997, but actually yielded "
                          + ((i + 1) % 12) + "/" + cal2.get(DAY_OF_MONTH) + "/1997.");
              }
          }
  
--- 1036,82 ---
          Calendar cur = (Calendar) cal.clone();
          int initialDOW = cur.get(DAY_OF_WEEK);
          int DOW, newDOW = initialDOW;
          do {
              DOW = newDOW;
!             System.out.println("DOW = " + DOW + "  " + cur.getTime());
  
              cur.add(DAY_OF_WEEK, delta);
              newDOW = cur.get(DAY_OF_WEEK);
              int expectedDOW = 1 + (DOW + delta - 1) % 7;
              if (newDOW != expectedDOW) {
!                 fail("Day of week should be " + expectedDOW
                          + " instead of " + newDOW + " on " + cur.getTime());
                  return;
              }
          } while (newDOW != initialDOW);
      }
  
+     @Test
      public void TestActualMinMax() {
          Calendar cal = new GregorianCalendar(1967, MARCH, 10);
          cal.setFirstDayOfWeek(SUNDAY);
          cal.setMinimalDaysInFirstWeek(3);
  
          if (cal.getActualMinimum(DAY_OF_MONTH) != 1) {
!             fail("Actual minimum date for 3/10/1967 should have been 1; got "
                      + cal.getActualMinimum(DAY_OF_MONTH));
          }
          if (cal.getActualMaximum(DAY_OF_MONTH) != 31) {
!             fail("Actual maximum date for 3/10/1967 should have been 31; got "
                      + cal.getActualMaximum(DAY_OF_MONTH));
          }
  
          cal.set(MONTH, FEBRUARY);
          if (cal.getActualMaximum(DAY_OF_MONTH) != 28) {
!             fail("Actual maximum date for 2/10/1967 should have been 28; got "
                      + cal.getActualMaximum(DAY_OF_MONTH));
          }
          if (cal.getActualMaximum(DAY_OF_YEAR) != 365) {
!             fail("Number of days in 1967 should have been 365; got "
                      + cal.getActualMaximum(DAY_OF_YEAR));
          }
  
          cal.set(YEAR, 1968);
          if (cal.getActualMaximum(DAY_OF_MONTH) != 29) {
!             fail("Actual maximum date for 2/10/1968 should have been 29; got "
                      + cal.getActualMaximum(DAY_OF_MONTH));
          }
          if (cal.getActualMaximum(DAY_OF_YEAR) != 366) {
!             fail("Number of days in 1968 should have been 366; got "
                      + cal.getActualMaximum(DAY_OF_YEAR));
          }
          // Using week settings of SUNDAY/3 (see above)
          if (cal.getActualMaximum(WEEK_OF_YEAR) != 52) {
!             fail("Number of weeks in 1968 should have been 52; got "
                      + cal.getActualMaximum(WEEK_OF_YEAR));
          }
  
          cal.set(YEAR, 1976);
          // Using week settings of SUNDAY/3 (see above)
          if (cal.getActualMaximum(WEEK_OF_YEAR) != 53) {
!             fail("Number of weeks in 1976 should have been 53; got "
                      + cal.getActualMaximum(WEEK_OF_YEAR));
          }
      }
  
+     @Test
      public void TestRoll() {
          Calendar cal = new GregorianCalendar(1997, JANUARY, 31);
  
          int[] dayValues = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31};
  
          for (int i = 0; i < dayValues.length; i++) {
              Calendar cal2 = (Calendar) cal.clone();
              cal2.roll(MONTH, i);
              if (cal2.get(DAY_OF_MONTH) != dayValues[i]) {
!                 fail("Rolling the month in 1/31/1997 up by " + i + " should have yielded "
                          + ((i + 1) % 12) + "/" + dayValues[i] + "/1997, but actually yielded "
                          + ((i + 1) % 12) + "/" + cal2.get(DAY_OF_MONTH) + "/1997.");
              }
          }
  

*** 1103,11 ***
          for (int i = 0; i < dayValues2.length; i++) {
              Calendar cal2 = (Calendar) cal.clone();
              cal2.roll(YEAR, i);
              if (cal2.get(DAY_OF_MONTH) != dayValues2[i] || cal2.get(MONTH)
                      != monthValues[i]) {
!                 errln("Rolling the year in 2/29/1996 up by " + i + " should have yielded "
                          + (monthValues[i] + 1) + "/" + dayValues2[i] + "/"
                          + (1996 + i) + ", but actually yielded "
                          + (cal2.get(MONTH) + 1) + "/"
                          + cal2.get(DAY_OF_MONTH) + "/" + (1996 + i) + ".");
              }
--- 1123,11 ---
          for (int i = 0; i < dayValues2.length; i++) {
              Calendar cal2 = (Calendar) cal.clone();
              cal2.roll(YEAR, i);
              if (cal2.get(DAY_OF_MONTH) != dayValues2[i] || cal2.get(MONTH)
                      != monthValues[i]) {
!                 fail("Rolling the year in 2/29/1996 up by " + i + " should have yielded "
                          + (monthValues[i] + 1) + "/" + dayValues2[i] + "/"
                          + (1996 + i) + ", but actually yielded "
                          + (cal2.get(MONTH) + 1) + "/"
                          + cal2.get(DAY_OF_MONTH) + "/" + (1996 + i) + ".");
              }

*** 1116,45 ***
          // Test rolling hour of day
          cal.set(HOUR_OF_DAY, 0);
          cal.roll(HOUR_OF_DAY, -2);
          int f = cal.get(HOUR_OF_DAY);
          if (f != 22) {
!             errln("Rolling HOUR_OF_DAY=0 delta=-2 gave " + f + " Wanted 22");
          }
          cal.roll(HOUR_OF_DAY, 5);
          f = cal.get(HOUR_OF_DAY);
          if (f != 3) {
!             errln("Rolling HOUR_OF_DAY=22 delta=5 gave " + f + " Wanted 3");
          }
          cal.roll(HOUR_OF_DAY, 21);
          f = cal.get(HOUR_OF_DAY);
          if (f != 0) {
!             errln("Rolling HOUR_OF_DAY=3 delta=21 gave " + f + " Wanted 0");
          }
  
          // Test rolling hour
          cal.set(HOUR_OF_DAY, 0);
          cal.roll(HOUR, -2);
          f = cal.get(HOUR);
          if (f != 10) {
!             errln("Rolling HOUR=0 delta=-2 gave " + f + " Wanted 10");
          }
          cal.roll(HOUR, 5);
          f = cal.get(HOUR);
          if (f != 3) {
!             errln("Rolling HOUR=10 delta=5 gave " + f + " Wanted 3");
          }
          cal.roll(HOUR, 9);
          f = cal.get(HOUR);
          if (f != 0) {
!             errln("Rolling HOUR=3 delta=9 gave " + f + " Wanted 0");
          }
      }
  
      /*
       * Confirm that multiple calls to Calendar.set() works correctly.
       */
      public void Test4374886() {
          Locale savedLocale = Locale.getDefault();
          TimeZone savedTimeZone = TimeZone.getDefault();
  
          try {
--- 1136,46 ---
          // Test rolling hour of day
          cal.set(HOUR_OF_DAY, 0);
          cal.roll(HOUR_OF_DAY, -2);
          int f = cal.get(HOUR_OF_DAY);
          if (f != 22) {
!             fail("Rolling HOUR_OF_DAY=0 delta=-2 gave " + f + " Wanted 22");
          }
          cal.roll(HOUR_OF_DAY, 5);
          f = cal.get(HOUR_OF_DAY);
          if (f != 3) {
!             fail("Rolling HOUR_OF_DAY=22 delta=5 gave " + f + " Wanted 3");
          }
          cal.roll(HOUR_OF_DAY, 21);
          f = cal.get(HOUR_OF_DAY);
          if (f != 0) {
!             fail("Rolling HOUR_OF_DAY=3 delta=21 gave " + f + " Wanted 0");
          }
  
          // Test rolling hour
          cal.set(HOUR_OF_DAY, 0);
          cal.roll(HOUR, -2);
          f = cal.get(HOUR);
          if (f != 10) {
!             fail("Rolling HOUR=0 delta=-2 gave " + f + " Wanted 10");
          }
          cal.roll(HOUR, 5);
          f = cal.get(HOUR);
          if (f != 3) {
!             fail("Rolling HOUR=10 delta=5 gave " + f + " Wanted 3");
          }
          cal.roll(HOUR, 9);
          f = cal.get(HOUR);
          if (f != 0) {
!             fail("Rolling HOUR=3 delta=9 gave " + f + " Wanted 0");
          }
      }
  
      /*
       * Confirm that multiple calls to Calendar.set() works correctly.
       */
+     @Test
      public void Test4374886() {
          Locale savedLocale = Locale.getDefault();
          TimeZone savedTimeZone = TimeZone.getDefault();
  
          try {

*** 1169,18 ***
  
              if (cal.get(YEAR) != 2001
                      || cal.get(MONTH) != JANUARY
                      || cal.get(DATE) != 22
                      || cal.get(DAY_OF_WEEK) != MONDAY) {
!                 errln("Failed : got " + cal.getTime() + ", expected Mon Jan 22, 2001");
              }
          } finally {
              Locale.setDefault(savedLocale);
              TimeZone.setDefault(savedTimeZone);
          }
      }
  
      public void TestClonedSharedZones() throws NoSuchFieldException, IllegalAccessException {
          Field zone = Calendar.class.getDeclaredField("zone");
          zone.setAccessible(true);
          Field sharedZone = Calendar.class.getDeclaredField("sharedZone");
          sharedZone.setAccessible(true);
--- 1190,19 ---
  
              if (cal.get(YEAR) != 2001
                      || cal.get(MONTH) != JANUARY
                      || cal.get(DATE) != 22
                      || cal.get(DAY_OF_WEEK) != MONDAY) {
!                 fail("Failed : got " + cal.getTime() + ", expected Mon Jan 22, 2001");
              }
          } finally {
              Locale.setDefault(savedLocale);
              TimeZone.setDefault(savedTimeZone);
          }
      }
  
+     @Test
      public void TestClonedSharedZones() throws NoSuchFieldException, IllegalAccessException {
          Field zone = Calendar.class.getDeclaredField("zone");
          zone.setAccessible(true);
          Field sharedZone = Calendar.class.getDeclaredField("sharedZone");
          sharedZone.setAccessible(true);

*** 1189,17 ***
          Calendar c1 = new GregorianCalendar();
          Calendar c2 = (Calendar) c1.clone();
  
          // c1 should have a shared zone
          if (!sharedZone.getBoolean(c1)) {
!             errln("Failed : c1.sharedZone == false");
          } else {
              // c2 should have a shared zone too
              if (!sharedZone.getBoolean(c2)) {
!                 errln("Failed : c2.sharedZone == false");
              } else if (zone.get(c1) != zone.get(c2)) {
!                 errln("Failed : c1.zone != c2.zone");
              }
          }
      }
  }
  
--- 1211,17 ---
          Calendar c1 = new GregorianCalendar();
          Calendar c2 = (Calendar) c1.clone();
  
          // c1 should have a shared zone
          if (!sharedZone.getBoolean(c1)) {
!             fail("Failed : c1.sharedZone == false");
          } else {
              // c2 should have a shared zone too
              if (!sharedZone.getBoolean(c2)) {
!                 fail("Failed : c2.sharedZone == false");
              } else if (zone.get(c1) != zone.get(c2)) {
!                 fail("Failed : c1.zone != c2.zone");
              }
          }
      }
  }
  
< prev index next >