< prev index next >

test/jdk/java/util/Calendar/bug4409072.java

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

*** 24,29 ***
  /*
   * @test
   * @bug 4409072
   * @summary tests for set(), add(), and roll() with various week parameters.
   * @library /java/text/testlib
!  * @run main bug4409072
   */
  
  import  java.util.*;
  import static java.util.Calendar.*;
  
! public class bug4409072 extends IntlTest {
  
!     public static void main(String[] args) throws Exception {
!         new bug4409072().run(args);
!     }
  
      /* Confirm some public methods' behavior in Calendar.
       * (e.g. add(), roll(), set())
       */
      public void Test4409072() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             logln("Skipping this test because locale is " + locale);
              return;
          }
  
          Locale savedLocale = Locale.getDefault();
          TimeZone savedTZ = TimeZone.getDefault();
--- 24,30 ---
  /*
   * @test
   * @bug 4409072
   * @summary tests for set(), add(), and roll() with various week parameters.
   * @library /java/text/testlib
!  * @run junit bug4409072
   */
  
  import  java.util.*;
  import static java.util.Calendar.*;
  
! import org.junit.jupiter.api.Test;
  
! import static org.junit.jupiter.api.Assertions.fail;
! 
! public class bug4409072 {
  
      /* Confirm some public methods' behavior in Calendar.
       * (e.g. add(), roll(), set())
       */
+     @Test
      public void Test4409072() {
          Locale locale = Locale.getDefault();
          if (!TestUtils.usesGregorianCalendar(locale)) {
!             System.out.println("Skipping this test because locale is " + locale);
              return;
          }
  
          Locale savedLocale = Locale.getDefault();
          TimeZone savedTZ = TimeZone.getDefault();

*** 409,20 ***
                  int month = cal.get(MONTH);
                  int date = cal.get(DATE);
  
                  if (cal.get(WEEK_OF_YEAR) != 22) {
                      noerror = false;
!                     errln("Failed : set(WEEK_OF_YEAR=22)" +
                            " *** get(WEEK_OF_YEAR=" +
                            cal.get(WEEK_OF_YEAR) + ")" +
                            ", got " + (month+1)+"/"+date+"/"+year +
                            ", expected " + (m+1)+"/"+d+"/"+2005 +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  } else if ((year != y) || (month != m) || (date != d)) {
                      noerror = false;
!                     errln("Failed : set(WEEK_OF_YEAR=22)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected " + (m+1)+"/"+d+"/"+y +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }
--- 410,20 ---
                  int month = cal.get(MONTH);
                  int date = cal.get(DATE);
  
                  if (cal.get(WEEK_OF_YEAR) != 22) {
                      noerror = false;
!                     fail("Failed : set(WEEK_OF_YEAR=22)" +
                            " *** get(WEEK_OF_YEAR=" +
                            cal.get(WEEK_OF_YEAR) + ")" +
                            ", got " + (month+1)+"/"+date+"/"+year +
                            ", expected " + (m+1)+"/"+d+"/"+2005 +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  } else if ((year != y) || (month != m) || (date != d)) {
                      noerror = false;
!                     fail("Failed : set(WEEK_OF_YEAR=22)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected " + (m+1)+"/"+d+"/"+y +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }

*** 444,11 ***
                      month = cal.get(MONTH);
                      date = cal.get(DATE);
  
                      if ((year != y) || (month != m) || (date != d)) {
                          noerror = false;
!                         errln("Failed : set(WEEK_OF_MONTH=1)" +
                                " got " + (month+1)+"/"+date+"/"+year +
                                ", expected " + (m+1)+"/"+d+"/"+y +
                                ", MinFirstDOW=" + minDow +
                                ", FirstDOW=" + dow);
                      }
--- 445,11 ---
                      month = cal.get(MONTH);
                      date = cal.get(DATE);
  
                      if ((year != y) || (month != m) || (date != d)) {
                          noerror = false;
!                         fail("Failed : set(WEEK_OF_MONTH=1)" +
                                " got " + (month+1)+"/"+date+"/"+year +
                                ", expected " + (m+1)+"/"+d+"/"+y +
                                ", MinFirstDOW=" + minDow +
                                ", FirstDOW=" + dow);
                      }

*** 468,31 ***
                      month = cal.get(MONTH);
                      date = cal.get(DATE);
  
                      if (cal.get(WEEK_OF_YEAR) != 1) {
                          noerror = false;
!                         errln("Failed : set(WEEK_OF_YEAR=1)" +
                                " *** get(WEEK_OF_YEAR=" +
                                cal.get(WEEK_OF_YEAR) + ")" +
                                ", got " + (month+1)+"/"+date+"/"+year +
                                ", expected " + (m+1)+"/"+d+"/"+y +
                                ", MinFirstDOW=" + minDow +
                                ", FirstDOW=" + dow);
                      } else if ((year != y) || (month != m) || (date != d)) {
                          noerror = false;
!                         errln("Failed : set(WEEK_OF_YEAR=1)" +
                                " got " + (month+1)+"/"+date+"/"+year +
                                ", expected " + (m+1)+"/"+d+"/"+y +
                                ", MinFirstDOW=" + minDow +
                                ", FirstDOW=" + dow);
                      }
                  }
              }
          }
  
          if (noerror) {
!             logln("Passed : set() test");
          }
      }
  
      /**
       * Test for add()
--- 469,31 ---
                      month = cal.get(MONTH);
                      date = cal.get(DATE);
  
                      if (cal.get(WEEK_OF_YEAR) != 1) {
                          noerror = false;
!                         fail("Failed : set(WEEK_OF_YEAR=1)" +
                                " *** get(WEEK_OF_YEAR=" +
                                cal.get(WEEK_OF_YEAR) + ")" +
                                ", got " + (month+1)+"/"+date+"/"+year +
                                ", expected " + (m+1)+"/"+d+"/"+y +
                                ", MinFirstDOW=" + minDow +
                                ", FirstDOW=" + dow);
                      } else if ((year != y) || (month != m) || (date != d)) {
                          noerror = false;
!                         fail("Failed : set(WEEK_OF_YEAR=1)" +
                                " got " + (month+1)+"/"+date+"/"+year +
                                ", expected " + (m+1)+"/"+d+"/"+y +
                                ", MinFirstDOW=" + minDow +
                                ", FirstDOW=" + dow);
                      }
                  }
              }
          }
  
          if (noerror) {
!             System.out.println("Passed : set() test");
          }
      }
  
      /**
       * Test for add()

*** 523,11 ***
                  int month = cal.get(MONTH);
                  int date = cal.get(DATE);
  
                  if ((year != 2006) || (month != 0) || (date != 25)) {
                      noerror = false;
!                     errln("Failed : add(WEEK_OF_YEAR+1)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected 1/25/2006" +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }
--- 524,11 ---
                  int month = cal.get(MONTH);
                  int date = cal.get(DATE);
  
                  if ((year != 2006) || (month != 0) || (date != 25)) {
                      noerror = false;
!                     fail("Failed : add(WEEK_OF_YEAR+1)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected 1/25/2006" +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }

*** 540,29 ***
                  year = cal.get(YEAR);
                  month = cal.get(MONTH);
                  date = cal.get(DATE);
  
                  if ((oldWOY - newWOY) != 3) {
!                     errln("Failed : add(WEEK_OF_YEAR-1)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected 11/16/2005" +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow +
                            ", WEEK_OF_YEAR=" + newWOY +
                            " should be " + (oldWOY-3));
                  } else if ((year != 2005) || (month != 10) || (date != 16)) {
!                     errln("Failed : add(-1)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected 11/16/2005" +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }
              }
          }
  
          if (noerror) {
!             logln("Passed : add() test");
          }
      }
  
      /*
       * Golden data for roll() test
--- 541,29 ---
                  year = cal.get(YEAR);
                  month = cal.get(MONTH);
                  date = cal.get(DATE);
  
                  if ((oldWOY - newWOY) != 3) {
!                     fail("Failed : add(WEEK_OF_YEAR-1)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected 11/16/2005" +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow +
                            ", WEEK_OF_YEAR=" + newWOY +
                            " should be " + (oldWOY-3));
                  } else if ((year != 2005) || (month != 10) || (date != 16)) {
!                     fail("Failed : add(-1)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected 11/16/2005" +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }
              }
          }
  
          if (noerror) {
!             System.out.println("Passed : add() test");
          }
      }
  
      /*
       * Golden data for roll() test

*** 620,11 ***
                  int month = cal.get(MONTH);
                  int date = cal.get(DATE);
  
                  if ((year != y) || (month != m) || (date != d)) {
                      noerror = false;
!                     errln("Failed : roll(WEEK_OF_MONTH-1)" +
                            " got " + (month+1) + "/" + date + "/" + year +
                            ", expected " + (m+1) + "/" + d + "/" + y +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }
--- 621,11 ---
                  int month = cal.get(MONTH);
                  int date = cal.get(DATE);
  
                  if ((year != y) || (month != m) || (date != d)) {
                      noerror = false;
!                     fail("Failed : roll(WEEK_OF_MONTH-1)" +
                            " got " + (month+1) + "/" + date + "/" + year +
                            ", expected " + (m+1) + "/" + d + "/" + y +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }

*** 647,11 ***
                  month = cal.get(MONTH);
                  date = cal.get(DATE);
  
                  if ((year != y) || (month != m) || (date != d)) {
                      noerror = false;
!                     errln("Failed : roll(WEEK_OF_YEAR+1)" +
                            " got " + (month+1) + "/" + date + "/" + year +
                            ", expected " + (m+1) + "/" + d + "/" + y +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }
--- 648,11 ---
                  month = cal.get(MONTH);
                  date = cal.get(DATE);
  
                  if ((year != y) || (month != m) || (date != d)) {
                      noerror = false;
!                     fail("Failed : roll(WEEK_OF_YEAR+1)" +
                            " got " + (month+1) + "/" + date + "/" + year +
                            ", expected " + (m+1) + "/" + d + "/" + y +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }

*** 668,19 ***
                  month = cal.get(MONTH);
                  date = cal.get(DATE);
  
                  if ((year != y) || (month != m) || (date != d)) {
                      noerror = false;
!                     errln("Failed : roll(WEEK_OF_YEAR-1)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected " + (m+1)+"/"+d+"/"+y +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }
              }
          }
  
          if (noerror) {
!             logln("Passed : roll() test");
          }
      }
  }
--- 669,19 ---
                  month = cal.get(MONTH);
                  date = cal.get(DATE);
  
                  if ((year != y) || (month != m) || (date != d)) {
                      noerror = false;
!                     fail("Failed : roll(WEEK_OF_YEAR-1)" +
                            " got " + (month+1)+"/"+date+"/"+year +
                            ", expected " + (m+1)+"/"+d+"/"+y +
                            ", MinFirstDOW=" + minDow +
                            ", FirstDOW=" + dow);
                  }
              }
          }
  
          if (noerror) {
!             System.out.println("Passed : roll() test");
          }
      }
  }
< prev index next >