1/* GENERATED SOURCE. DO NOT MODIFY. */ 2/* 3 ******************************************************************************* 4 * Copyright (C) 1996-2013, International Business Machines Corporation and * 5 * others. All Rights Reserved. * 6 ******************************************************************************* 7 */ 8 9package android.icu.dev.test.calendar; 10import java.util.Date; 11import java.util.Locale; 12import java.util.MissingResourceException; 13 14import android.icu.impl.LocaleUtility; 15import android.icu.text.DateFormat; 16import android.icu.util.Calendar; 17import android.icu.util.HebrewCalendar; 18import android.icu.util.TimeZone; 19import android.icu.util.ULocale; 20import org.junit.runner.RunWith; 21import android.icu.junit.IcuTestFmwkRunner; 22 23/** 24 * Tests for the <code>HebrewCalendar</code> class. 25 */ 26@RunWith(IcuTestFmwkRunner.class) 27public class HebrewTest extends CalendarTest { 28 public static void main(String args[]) throws Exception { 29 new HebrewTest().run(args); 30 } 31 32 // Constants to save typing. 33 public static final int TISHRI = HebrewCalendar.TISHRI; 34 public static final int HESHVAN = HebrewCalendar.HESHVAN; 35 public static final int KISLEV = HebrewCalendar.KISLEV; 36 public static final int TEVET = HebrewCalendar.TEVET; 37 public static final int SHEVAT = HebrewCalendar.SHEVAT; 38 public static final int ADAR_1 = HebrewCalendar.ADAR_1; 39 public static final int ADAR = HebrewCalendar.ADAR; 40 public static final int NISAN = HebrewCalendar.NISAN; 41 public static final int IYAR = HebrewCalendar.IYAR; 42 public static final int SIVAN = HebrewCalendar.SIVAN; 43 public static final int TAMUZ = HebrewCalendar.TAMUZ; 44 public static final int AV = HebrewCalendar.AV; 45 public static final int ELUL = HebrewCalendar.ELUL; 46 47 /** 48 * Test the behavior of HebrewCalendar.roll 49 * The only real nastiness with roll is the MONTH field, since a year can 50 * have a variable number of months. 51 */ 52 public void TestRoll() { 53 int[][] tests = new int[][] { 54 // input roll by output 55 // year month day field amount year month day 56 57 { 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 }, // non-leap years 58 { 5759, SHEVAT, 2, MONTH, 1, 5759, ADAR, 2 }, 59 { 5759, SHEVAT, 2, MONTH, 2, 5759, NISAN, 2 }, 60 { 5759, SHEVAT, 2, MONTH, 12, 5759, SHEVAT, 2 }, 61 { 5759, AV, 1, MONTH, 12, 5759, AV, 1 }, // Alan 62 63 { 5757, HESHVAN, 2, MONTH, 1, 5757, KISLEV, 2 }, // leap years 64 { 5757, SHEVAT, 2, MONTH, 1, 5757, ADAR_1, 2 }, 65 { 5757, SHEVAT, 2, MONTH, 2, 5757, ADAR, 2 }, 66 { 5757, SHEVAT, 2, MONTH, 3, 5757, NISAN, 2 }, 67 { 5757, SHEVAT, 2, MONTH, 12, 5757, TEVET, 2 }, 68 { 5757, SHEVAT, 2, MONTH, 13, 5757, SHEVAT, 2 }, 69 { 5757, AV, 1, MONTH, 12, 5757, TAMUZ, 1 }, // Alan 70 71 { 5757, KISLEV, 1, DATE, 30, 5757, KISLEV, 2 }, // 29-day month 72 { 5758, KISLEV, 1, DATE, 31, 5758, KISLEV, 2 }, // 30-day month 73 74 // Try some other fields too 75 { 5757, TISHRI, 1, YEAR, 1, 5758, TISHRI, 1 }, 76 77 78 // Try some rolls that require other fields to be adjusted 79 { 5757, TISHRI, 30, MONTH, 1, 5757, HESHVAN, 29 }, 80 { 5758, KISLEV, 30, YEAR, -1, 5757, KISLEV, 29 }, 81 }; 82// try{ 83 HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault()); 84 85 doRollAdd(ROLL, cal, tests); 86 // }catch(MissingResourceException ex){ 87// warnln("Got Exception: "+ ex.getMessage()); 88 // } 89 } 90 91 /** 92 * Test the behavior of HebrewCalendar.roll 93 * The only real nastiness with roll is the MONTH field, since a year can 94 * have a variable number of months. 95 */ 96 public void TestAdd() { 97 int[][] tests = new int[][] { 98 // input add by output 99 // year month day field amount year month day 100 { 5759, HESHVAN, 2, MONTH, 1, 5759, KISLEV, 2 }, // non-leap years 101 { 5759, SHEVAT, 2, MONTH, 1, 5759, ADAR, 2 }, 102 { 5759, SHEVAT, 2, MONTH, 2, 5759, NISAN, 2 }, 103 { 5759, SHEVAT, 2, MONTH, 12, 5760, SHEVAT, 2 }, 104 105 { 5757, HESHVAN, 2, MONTH, 1, 5757, KISLEV, 2 }, // leap years 106 { 5757, SHEVAT, 2, MONTH, 1, 5757, ADAR_1, 2 }, 107 { 5757, SHEVAT, 2, MONTH, 2, 5757, ADAR, 2 }, 108 { 5757, SHEVAT, 2, MONTH, 3, 5757, NISAN, 2 }, 109 { 5757, SHEVAT, 2, MONTH, 12, 5758, TEVET, 2 }, 110 { 5757, SHEVAT, 2, MONTH, 13, 5758, SHEVAT, 2 }, 111 112 { 5762, AV, 1, MONTH, 1, 5762, ELUL, 1 }, // JB#2327 113 { 5762, AV, 30, DATE, 1, 5762, ELUL, 1 }, // JB#2327 114 { 5762, ELUL, 1, DATE, -1, 5762, AV, 30 }, // JB#2327 115 { 5762, ELUL, 1, MONTH, -1, 5762, AV, 1 }, // JB#2327 116 117 { 5757, KISLEV, 1, DATE, 30, 5757, TEVET, 2 }, // 29-day month 118 { 5758, KISLEV, 1, DATE, 31, 5758, TEVET, 2 }, // 30-day month 119 }; 120 try{ 121 HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault()); 122 123 doRollAdd(ADD, cal, tests); 124 }catch( MissingResourceException ex){ 125 warnln("Could not load the locale data"); 126 } 127 } 128 129 /** 130 * A huge list of test cases to make sure that computeTime and computeFields 131 * work properly for a wide range of data. 132 */ 133 public void TestCases() { 134 try{ 135 final TestCase[] testCases = { 136 // 137 // Most of these test cases were taken from the back of 138 // "Calendrical Calculations", with some extras added to help 139 // debug a few of the problems that cropped up in development. 140 // 141 // The months in this table are 1-based rather than 0-based, 142 // because it's easier to edit that way. 143 // 144 // Julian Day Era Year Month Day WkDay Hour Min Sec 145 new TestCase(1507231.5, 0, 3174, 12, 10, SUN, 0, 0, 0), 146 new TestCase(1660037.5, 0, 3593, 3, 25, WED, 0, 0, 0), 147 new TestCase(1746893.5, 0, 3831, 1, 3, WED, 0, 0, 0), 148 new TestCase(1770641.5, 0, 3896, 1, 9, SUN, 0, 0, 0), 149 new TestCase(1892731.5, 0, 4230, 4, 18, WED, 0, 0, 0), 150 new TestCase(1931579.5, 0, 4336, 10, 4, MON, 0, 0, 0), 151 new TestCase(1974851.5, 0, 4455, 2, 13, SAT, 0, 0, 0), 152 new TestCase(2091164.5, 0, 4773, 9, 6, SUN, 0, 0, 0), 153 new TestCase(2121509.5, 0, 4856, 9, 23, SUN, 0, 0, 0), 154 new TestCase(2155779.5, 0, 4950, 8, 7, FRI, 0, 0, 0), 155 new TestCase(2174029.5, 0, 5000, 7, 8, SAT, 0, 0, 0), 156 new TestCase(2191584.5, 0, 5048, 8, 21, FRI, 0, 0, 0), 157 new TestCase(2195261.5, 0, 5058, 9, 7, SUN, 0, 0, 0), 158 new TestCase(2229274.5, 0, 5151, 11, 1, SUN, 0, 0, 0), 159 new TestCase(2245580.5, 0, 5196, 5, 7, WED, 0, 0, 0), 160 new TestCase(2266100.5, 0, 5252, 8, 3, SAT, 0, 0, 0), 161 new TestCase(2288542.5, 0, 5314, 1, 1, SAT, 0, 0, 0), 162 new TestCase(2290901.5, 0, 5320, 6, 27, SAT, 0, 0, 0), 163 new TestCase(2323140.5, 0, 5408, 10, 20, WED, 0, 0, 0), 164 new TestCase(2334551.5, 0, 5440, 1, 1, THU, 0, 0, 0), 165 new TestCase(2334581.5, 0, 5440, 2, 1, SAT, 0, 0, 0), 166 new TestCase(2334610.5, 0, 5440, 3, 1, SUN, 0, 0, 0), 167 new TestCase(2334639.5, 0, 5440, 4, 1, MON, 0, 0, 0), 168 new TestCase(2334668.5, 0, 5440, 5, 1, TUE, 0, 0, 0), 169 new TestCase(2334698.5, 0, 5440, 6, 1, THU, 0, 0, 0), 170 new TestCase(2334728.5, 0, 5440, 7, 1, SAT, 0, 0, 0), 171 new TestCase(2334757.5, 0, 5440, 8, 1, SUN, 0, 0, 0), 172 new TestCase(2334787.5, 0, 5440, 9, 1, TUE, 0, 0, 0), 173 new TestCase(2334816.5, 0, 5440, 10, 1, WED, 0, 0, 0), 174 new TestCase(2334846.5, 0, 5440, 11, 1, FRI, 0, 0, 0), 175 new TestCase(2334848.5, 0, 5440, 11, 3, SUN, 0, 0, 0), 176 new TestCase(2334934.5, 0, 5441, 1, 1, TUE, 0, 0, 0), 177 new TestCase(2348020.5, 0, 5476, 12, 5, FRI, 0, 0, 0), 178 new TestCase(2366978.5, 0, 5528, 11, 4, SUN, 0, 0, 0), 179 new TestCase(2385648.5, 0, 5579, 12, 11, MON, 0, 0, 0), 180 new TestCase(2392825.5, 0, 5599, 8, 12, WED, 0, 0, 0), 181 new TestCase(2416223.5, 0, 5663, 8, 22, SUN, 0, 0, 0), 182 new TestCase(2425848.5, 0, 5689, 12, 19, SUN, 0, 0, 0), 183 new TestCase(2430266.5, 0, 5702, 1, 8, MON, 0, 0, 0), 184 new TestCase(2430833.5, 0, 5703, 8, 14, MON, 0, 0, 0), 185 new TestCase(2431004.5, 0, 5704, 1, 8, THU, 0, 0, 0), 186 new TestCase(2448698.5, 0, 5752, 7, 12, TUE, 0, 0, 0), 187 new TestCase(2450138.5, 0, 5756, 7, 5, SUN, 0, 0, 0), 188 new TestCase(2465737.5, 0, 5799, 2, 12, WED, 0, 0, 0), 189 new TestCase(2486076.5, 0, 5854, 12, 5, SUN, 0, 0, 0), 190 191 // Additional test cases for bugs found during development 192 // G.YY/MM/DD Era Year Month Day WkDay Hour Min Sec 193 new TestCase(1013, 9, 8, 0, 4774, 1, 1, TUE, 0, 0, 0), 194 new TestCase(1239, 9, 1, 0, 5000, 1, 1, THU, 0, 0, 0), 195 new TestCase(1240, 9,18, 0, 5001, 1, 1, TUE, 0, 0, 0), 196 197 // Test cases taken from a table of 14 "year types" in the Help file 198 // of the application "Hebrew Calendar" 199 new TestCase(2456187.5, 0, 5773, 1, 1, MON, 0, 0, 0), 200 new TestCase(2459111.5, 0, 5781, 1, 1, SAT, 0, 0, 0), 201 new TestCase(2453647.5, 0, 5766, 1, 1, TUE, 0, 0, 0), 202 new TestCase(2462035.5, 0, 5789, 1, 1, THU, 0, 0, 0), 203 new TestCase(2458756.5, 0, 5780, 1, 1, MON, 0, 0, 0), 204 new TestCase(2460586.5, 0, 5785, 1, 1, THU, 0, 0, 0), 205 new TestCase(2463864.5, 0, 5794, 1, 1, SAT, 0, 0, 0), 206 new TestCase(2463481.5, 0, 5793, 1, 1, MON, 0, 0, 0), 207 new TestCase(2470421.5, 0, 5812, 1, 1, THU, 0, 0, 0), 208 new TestCase(2460203.5, 0, 5784, 1, 1, SAT, 0, 0, 0), 209 new TestCase(2459464.5, 0, 5782, 1, 1, TUE, 0, 0, 0), 210 new TestCase(2467142.5, 0, 5803, 1, 1, MON, 0, 0, 0), 211 new TestCase(2455448.5, 0, 5771, 1, 1, THU, 0, 0, 0), 212 213 // Test cases for JB#2327 214 // http://www.fourmilab.com/documents/calendar/ 215 // http://www.calendarhome.com/converter/ 216// 2452465.5, 2002, JULY, 10, 5762, AV, 1, 217// 2452494.5, 2002, AUGUST, 8, 5762, AV, 30, 218// 2452495.5, 2002, AUGUST, 9, 5762, ELUL, 1, 219// 2452523.5, 2002, SEPTEMBER, 6, 5762, ELUL, 29, 220// 2452524.5, 2002, SEPTEMBER, 7, 5763, TISHRI, 1, 221 // Julian Day Era Year Month Day WkDay Hour Min Sec 222 new TestCase(2452465.5, 0, 5762, AV+1, 1, WED, 0, 0, 0), 223 new TestCase(2452494.5, 0, 5762, AV+1, 30, THU, 0, 0, 0), 224 new TestCase(2452495.5, 0, 5762, ELUL+1, 1, FRI, 0, 0, 0), 225 new TestCase(2452523.5, 0, 5762, ELUL+1, 29, FRI, 0, 0, 0), 226 new TestCase(2452524.5, 0, 5763,TISHRI+1, 1, SAT, 0, 0, 0), 227 }; 228 doTestCases(testCases, new HebrewCalendar()); 229 230 }catch(MissingResourceException ex){ 231 warnln("Got Exception: "+ ex.getMessage()); 232 } 233 } 234 235 /** 236 * Problem reported by Armand Bendanan in which setting of the MONTH 237 * field in a Hebrew calendar causes the time fields to go negative. 238 */ 239 public void TestTimeFields() { 240 try{ 241 HebrewCalendar calendar = new HebrewCalendar(5761, 0, 11, 12, 28, 15); 242 calendar.set(Calendar.YEAR, 5717); 243 calendar.set(Calendar.MONTH, 2); 244 calendar.set(Calendar.DAY_OF_MONTH, 23); 245 if (calendar.get(Calendar.HOUR_OF_DAY) != 12) { 246 errln("Fail: HebrewCalendar HOUR_OF_DAY = " + calendar.get(Calendar.HOUR_OF_DAY)); 247 } 248 }catch(MissingResourceException ex){ 249 warnln("Got Exception: "+ ex.getMessage()); 250 } 251 } 252 253 /** 254 * Problem reported by Armand Bendanan (armand.bendanan@free.fr) 255 * in which setting of the MONTH field in a Hebrew calendar to 256 * ELUL on non leap years causes the date to be set on TISHRI next year. 257 */ 258 public void TestElulMonth() { 259 try{ 260 HebrewCalendar cal = new HebrewCalendar(); 261 // Leap years are: 262 // 3 6 8 11 14 17 19 (and so on - 19-year cycle) 263 for (int year=1; year<50; year++) { 264 // I hope that year = 0 does not exists 265 // because the test fails for it ! 266 cal.clear(); 267 268 cal.set(Calendar.YEAR, year); 269 cal.set(Calendar.MONTH, ELUL); 270 cal.set(Calendar.DAY_OF_MONTH, 1); 271 272 int yact = cal.get(Calendar.YEAR); 273 int mact = cal.get(Calendar.MONTH); 274 275 if (year != yact || ELUL != mact) { 276 errln("Fail: " + ELUL + "/" + year + 277 " -> " + 278 mact + "/" + yact); 279 } 280 } 281 }catch(MissingResourceException ex){ 282 warnln("Got Exception: "+ ex.getMessage()); 283 } 284 } 285 286 /** 287 * Test of the behavior of the month field. This requires special 288 * handling in the Hebrew calendar because of the pattern of leap 289 * years. 290 */ 291 public void TestMonthMovement() { 292 try{ 293 HebrewCalendar cal = new HebrewCalendar(); 294 // Leap years are: 295 // 3 6 8 11 14 17 19 (and so on - 19-year cycle) 296 // We can't test complete() on some lines below because of ADAR_1 -- if 297 // the calendar is set to ADAR_1 on a non-leap year, the result is undefined. 298 int[] DATA = { 299 // m1/y1 - month/year before (month is 1-based) 300 // delta - amount to add to month field 301 // m2/y2 - month/year after add(MONTH, delta) 302 // m3/y3 - month/year after set(MONTH, m1+delta) 303 //m1 y1 delta m2 y2 m3 y3 304 10, 2, +24, 9, 4, 9, 4, 305 10, 2, +60, 8, 7, 8, 7, 306 1 , 2, +12, 1, 3, 13, 2, //*set != add; also see '*' below 307 3 , 18, -24, 4, 16, 4, 16, 308 1 , 6, -24, 1, 4, 1, 4, 309 4 , 3, +2, 6, 3, 6, 3, // Leap year - no skip 4,5,6,7,8 310 8 , 3, -2, 6, 3, 6, 3, // Leap year - no skip 311 4 , 2, +2, 7, 2, 7, 2, // Skip leap month 4,5,(6),7,8 312 8 , 2, -2, 5, 2, 7, 2, //*Skip leap month going backward 313 }; 314 for (int i=0; i<DATA.length; ) { 315 int m = DATA[i++], y = DATA[i++]; 316 int monthDelta = DATA[i++]; 317 int m2 = DATA[i++], y2 = DATA[i++]; 318 int m3 = DATA[i++], y3 = DATA[i++]; 319 int mact, yact; 320 321 cal.clear(); 322 cal.set(Calendar.YEAR, y); 323 cal.set(Calendar.MONTH, m-1); 324 cal.add(Calendar.MONTH, monthDelta); 325 yact = cal.get(Calendar.YEAR); mact = cal.get(Calendar.MONTH) + 1; 326 if (y2 != yact || m2 != mact) { 327 errln("Fail: " + m + "/" + y + 328 " -> add(MONTH, " + monthDelta + ") -> " + 329 mact + "/" + yact + ", expected " + 330 m2 + "/" + y2); 331 cal.clear(); 332 cal.set(Calendar.YEAR, y); 333 cal.set(Calendar.MONTH, m-1); 334 logln("Start: " + m + "/" + y); 335 int delta = monthDelta > 0 ? 1 : -1; 336 for (int c=0; c!=monthDelta; c+=delta) { 337 cal.add(Calendar.MONTH, delta); 338 logln("+ " + delta + " MONTH -> " + 339 (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR)); 340 } 341 } 342 343 cal.clear(); 344 cal.set(Calendar.YEAR, y); 345 cal.set(Calendar.MONTH, m + monthDelta - 1); 346 yact = cal.get(Calendar.YEAR); mact = cal.get(Calendar.MONTH) + 1; 347 if (y3 != yact || m3 != mact) { 348 errln("Fail: " + (m+monthDelta) + "/" + y + 349 " -> complete() -> " + 350 mact + "/" + yact + ", expected " + 351 m3 + "/" + y3); 352 } 353 } 354 }catch(MissingResourceException ex){ 355 warnln("Got Exception: "+ ex.getMessage()); 356 } 357 } 358 359 /** 360 * Test handling of ADAR_1. 361 */ 362 /* 363 public void TestAdar1() { 364 HebrewCalendar cal = new HebrewCalendar(); 365 cal.clear(); 366 cal.set(Calendar.YEAR, 1903); // leap 367 cal.set(Calendar.MONTH, HebrewCalendar.ADAR_1); 368 logln("1903(leap)/ADAR_1 => " + 369 cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH)+1)); 370 371 cal.clear(); 372 cal.set(Calendar.YEAR, 1904); // non-leap 373 cal.set(Calendar.MONTH, HebrewCalendar.ADAR_1); 374 logln("1904(non-leap)/ADAR_1 => " + 375 cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH)+1)); 376 } 377 */ 378 379 /** 380 * With no fields set, the calendar should use default values. 381 */ 382 public void TestDefaultFieldValues() { 383 try{ 384 HebrewCalendar cal = new HebrewCalendar(); 385 cal.clear(); 386 logln("cal.clear() -> " + cal.getTime()); 387 }catch(MissingResourceException ex){ 388 warnln("could not load the locale data"); 389 } 390 } 391 392 /** 393 * Test limits of the Hebrew calendar 394 */ 395 public void TestLimits() { 396 Calendar cal = Calendar.getInstance(); 397 cal.set(2007, Calendar.JANUARY, 1); 398 HebrewCalendar hebrew = new HebrewCalendar(); 399 doLimitsTest(hebrew, null, cal.getTime()); 400 doTheoreticalLimitsTest(hebrew, true); 401 } 402 403 public void TestCoverage() { 404 try{ 405 { 406 // new HebrewCalendar(TimeZone) 407 HebrewCalendar cal = new HebrewCalendar(TimeZone.getDefault()); 408 if(cal == null){ 409 errln("could not create HebrewCalendar with TimeZone"); 410 } 411 } 412 413 { 414 // new HebrewCalendar(ULocale) 415 HebrewCalendar cal = new HebrewCalendar(ULocale.getDefault()); 416 if(cal == null){ 417 errln("could not create HebrewCalendar with ULocale"); 418 } 419 } 420 421 { 422 // new HebrewCalendar(Locale) 423 HebrewCalendar cal = new HebrewCalendar(Locale.getDefault()); 424 if(cal == null){ 425 errln("could not create HebrewCalendar with locale"); 426 } 427 } 428 429 { 430 // new HebrewCalendar(Date) 431 HebrewCalendar cal = new HebrewCalendar(new Date()); 432 if(cal == null){ 433 errln("could not create HebrewCalendar with date"); 434 } 435 } 436 437 { 438 // data 439 HebrewCalendar cal = new HebrewCalendar(2800, HebrewCalendar.SHEVAT, 1); 440 Date time = cal.getTime(); 441 442 String[] calendarLocales = { 443 "iw_IL" 444 }; 445 446 String[] formatLocales = { 447 "en", "fi", "fr", "hu", "iw", "nl" 448 }; 449 for (int i = 0; i < calendarLocales.length; ++i) { 450 String calLocName = calendarLocales[i]; 451 Locale calLocale = LocaleUtility.getLocaleFromName(calLocName); 452 cal = new HebrewCalendar(calLocale); 453 454 for (int j = 0; j < formatLocales.length; ++j) { 455 String locName = formatLocales[j]; 456 Locale formatLocale = LocaleUtility.getLocaleFromName(locName); 457 DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale); 458 logln(calLocName + "/" + locName + " --> " + format.format(time)); 459 } 460 } 461 } 462 }catch( MissingResourceException ex){ 463 warnln("Could not load the locale data. "+ ex.getMessage()); 464 } 465 } 466 public void Test1624() { 467 468 HebrewCalendar hc = new HebrewCalendar (5742, HebrewCalendar.AV, 22); 469 DateFormat df = hc.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, Locale.getDefault()); 470 String dateString = df.format(hc.getTime()); 471 472 for (int year = 5600; year < 5800; year ++) { 473 boolean leapYear = HebrewCalendar.isLeapYear (year); 474 for (int month = HebrewCalendar.TISHRI; month <= HebrewCalendar.ELUL;month++) { 475 // skip the adar 1 month if year is not a leap year 476 if (leapYear == false && month == HebrewCalendar.ADAR_1) { 477 continue; 478 } 479 int day = 15; 480 hc = new HebrewCalendar (year, month, day); 481 482 dateString = df.format(hc.getTime()); 483 int dayHC = hc.get (HebrewCalendar.DATE); 484 int monthHC = hc.get (HebrewCalendar.MONTH); 485 int yearHC = hc.get (HebrewCalendar.YEAR); 486 487 String header = "year:" + year + " isleap:" + leapYear + " " + dateString; 488 if (dayHC != day) { 489 errln (header + " ==> day:" + dayHC + " incorrect, should be:" + day); 490 break; 491 } 492 if (monthHC != month) { 493 errln (header + " ==> month:" + monthHC + " incorrect, should be:" + month); 494 break; 495 } 496 if (yearHC != year) { 497 errln (header + " ==> year:" + yearHC + " incorrecte, should be:" + year); 498 break; 499 } 500 } 501 } 502 } 503 504 // Test case for Ticket#10313. HebrewCalendar requires 505 // special handling for validating month value, because 506 // month Adar I is only available in leap years. 507 public void TestMonthValidation() { 508 HebrewCalendar cal = new HebrewCalendar(); 509 cal.setLenient(false); 510 511 // 5776 is a leap year and has month Adar I 512 cal.set(5776, ADAR_1, 1); 513 try { 514 /* Date d = */ cal.getTime(); 515 } catch (IllegalArgumentException e) { 516 errln("Fail: 5776 Adar I 1 is a valid date."); 517 } 518 519 // 5777 is NOT a lear year and does not have month Adar I 520 cal.set(5777, ADAR_1, 1); 521 try { 522 /* Date d = */ cal.getTime(); 523 errln("Fail: IllegalArgumentException should be thrown for input date 5777 Adar I 1."); 524 } catch (IllegalArgumentException e) { 525 logln("Info: IllegalArgumentException, because 5777 Adar I 1 is not a valid date."); 526 } 527 } 528} 529