1 /* 2 * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * * Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * * Neither the name of JSR-310 nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.threeten.bp.zone; 33 34 import static org.testng.Assert.assertEquals; 35 36 import java.io.File; 37 import java.lang.reflect.InvocationTargetException; 38 import java.lang.reflect.Method; 39 import java.util.ArrayList; 40 import java.util.StringTokenizer; 41 42 import org.testng.annotations.Test; 43 import org.threeten.bp.DayOfWeek; 44 import org.threeten.bp.LocalDate; 45 import org.threeten.bp.LocalTime; 46 import org.threeten.bp.Month; 47 import org.threeten.bp.Year; 48 import org.threeten.bp.zone.TzdbZoneRulesCompiler.LeapSecondRule; 49 import org.threeten.bp.zone.TzdbZoneRulesCompiler.TZDBMonthDayTime; 50 import org.threeten.bp.zone.TzdbZoneRulesCompiler.TZDBRule; 51 import org.threeten.bp.zone.ZoneOffsetTransitionRule.TimeDefinition; 52 53 /** 54 * Test TzdbZoneRulesCompiler. 55 */ 56 @Test 57 public class TestTzdbZoneRulesCompiler { 58 59 //----------------------------------------------------------------------- 60 // parseYear() 61 //----------------------------------------------------------------------- 62 @Test test_parseYear_specific()63 public void test_parseYear_specific() throws Exception { 64 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 65 assertEquals(parseYear(test, "2010", 2000), 2010); 66 } 67 68 @Test test_parseYear_min()69 public void test_parseYear_min() throws Exception { 70 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 71 assertEquals(parseYear(test, "min", 2000), Year.MIN_VALUE); 72 } 73 74 @Test test_parseYear_mini()75 public void test_parseYear_mini() throws Exception { 76 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 77 assertEquals(parseYear(test, "mini", 2000), Year.MIN_VALUE); 78 } 79 80 @Test test_parseYear_minim()81 public void test_parseYear_minim() throws Exception { 82 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 83 assertEquals(parseYear(test, "minim", 2000), Year.MIN_VALUE); 84 } 85 86 @Test test_parseYear_minimu()87 public void test_parseYear_minimu() throws Exception { 88 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 89 assertEquals(parseYear(test, "minimu", 2000), Year.MIN_VALUE); 90 } 91 92 @Test test_parseYear_minimum()93 public void test_parseYear_minimum() throws Exception { 94 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 95 assertEquals(parseYear(test, "minimum", 2000), Year.MIN_VALUE); 96 } 97 98 99 @Test(expectedExceptions=NumberFormatException.class) test_parseYear_minTooShort()100 public void test_parseYear_minTooShort() throws Exception { 101 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 102 parseYear(test, "mi", 2000); 103 } 104 105 @Test(expectedExceptions=NumberFormatException.class) test_parseYear_minTooLong()106 public void test_parseYear_minTooLong() throws Exception { 107 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 108 parseYear(test, "minimuma", 2000); 109 } 110 111 @Test test_parseYear_max()112 public void test_parseYear_max() throws Exception { 113 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 114 assertEquals(parseYear(test, "max", 2000), Year.MAX_VALUE); 115 } 116 117 @Test test_parseYear_maxi()118 public void test_parseYear_maxi() throws Exception { 119 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 120 assertEquals(parseYear(test, "maxi", 2000), Year.MAX_VALUE); 121 } 122 123 @Test test_parseYear_maxim()124 public void test_parseYear_maxim() throws Exception { 125 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 126 assertEquals(parseYear(test, "maxim", 2000), Year.MAX_VALUE); 127 } 128 129 @Test test_parseYear_maximu()130 public void test_parseYear_maximu() throws Exception { 131 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 132 assertEquals(parseYear(test, "maximu", 2000), Year.MAX_VALUE); 133 } 134 135 @Test test_parseYear_maximum()136 public void test_parseYear_maximum() throws Exception { 137 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 138 assertEquals(parseYear(test, "maximum", 2000), Year.MAX_VALUE); 139 } 140 141 @Test(expectedExceptions=NumberFormatException.class) test_parseYear_maxTooShort()142 public void test_parseYear_maxTooShort() throws Exception { 143 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 144 parseYear(test, "ma", 2000); 145 } 146 147 @Test(expectedExceptions=NumberFormatException.class) test_parseYear_maxTooLong()148 public void test_parseYear_maxTooLong() throws Exception { 149 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 150 parseYear(test, "maximuma", 2000); 151 } 152 153 @Test test_parseYear_only()154 public void test_parseYear_only() throws Exception { 155 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 156 assertEquals(parseYear(test, "only", 2000), 2000); 157 } 158 159 @Test test_parseYear_only_uppercase()160 public void test_parseYear_only_uppercase() throws Exception { 161 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 162 assertEquals(parseYear(test, "ONLY", 2000), 2000); 163 } 164 165 @Test(expectedExceptions=NumberFormatException.class) test_parseYear_invalidYear()166 public void test_parseYear_invalidYear() throws Exception { 167 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 168 parseYear(test, "ABC", 2000); 169 } 170 171 static final Method PARSE_YEAR; 172 static { 173 try { 174 PARSE_YEAR = TzdbZoneRulesCompiler.class.getDeclaredMethod("parseYear", String.class, Integer.TYPE); 175 PARSE_YEAR.setAccessible(true); 176 } catch (Exception ex) { 177 throw new RuntimeException(ex); 178 } 179 } parseYear(TzdbZoneRulesCompiler test, String str, int year)180 private int parseYear(TzdbZoneRulesCompiler test, String str, int year) throws Exception { 181 try { 182 return (Integer) PARSE_YEAR.invoke(test, str, year); 183 } catch (InvocationTargetException ex) { 184 if (ex.getCause() != null) { 185 throw (Exception) ex.getCause(); 186 } 187 throw ex; 188 } 189 } 190 191 //----------------------------------------------------------------------- 192 // parseMonth() 193 //----------------------------------------------------------------------- 194 @Test test_parseMonth()195 public void test_parseMonth() throws Exception { 196 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 197 assertEquals(parseMonth(test, "Jan"), Month.JANUARY); 198 assertEquals(parseMonth(test, "Feb"), Month.FEBRUARY); 199 assertEquals(parseMonth(test, "Mar"), Month.MARCH); 200 assertEquals(parseMonth(test, "Apr"), Month.APRIL); 201 assertEquals(parseMonth(test, "May"), Month.MAY); 202 assertEquals(parseMonth(test, "Jun"), Month.JUNE); 203 assertEquals(parseMonth(test, "Jul"), Month.JULY); 204 assertEquals(parseMonth(test, "Aug"), Month.AUGUST); 205 assertEquals(parseMonth(test, "Sep"), Month.SEPTEMBER); 206 assertEquals(parseMonth(test, "Oct"), Month.OCTOBER); 207 assertEquals(parseMonth(test, "Nov"), Month.NOVEMBER); 208 assertEquals(parseMonth(test, "Dec"), Month.DECEMBER); 209 assertEquals(parseMonth(test, "January"), Month.JANUARY); 210 assertEquals(parseMonth(test, "February"), Month.FEBRUARY); 211 assertEquals(parseMonth(test, "March"), Month.MARCH); 212 assertEquals(parseMonth(test, "April"), Month.APRIL); 213 assertEquals(parseMonth(test, "May"), Month.MAY); 214 assertEquals(parseMonth(test, "June"), Month.JUNE); 215 assertEquals(parseMonth(test, "July"), Month.JULY); 216 assertEquals(parseMonth(test, "August"), Month.AUGUST); 217 assertEquals(parseMonth(test, "September"), Month.SEPTEMBER); 218 assertEquals(parseMonth(test, "October"), Month.OCTOBER); 219 assertEquals(parseMonth(test, "November"), Month.NOVEMBER); 220 assertEquals(parseMonth(test, "December"), Month.DECEMBER); 221 assertEquals(parseMonth(test, "Janu"), Month.JANUARY); 222 assertEquals(parseMonth(test, "Janua"), Month.JANUARY); 223 assertEquals(parseMonth(test, "Januar"), Month.JANUARY); 224 } 225 226 @Test(expectedExceptions=IllegalArgumentException.class) test_parseMonth_invalidMonth()227 public void test_parseMonth_invalidMonth() throws Exception { 228 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 229 parseMonth(test, "ABC"); 230 } 231 232 static final Method PARSE_MONTH; 233 static { 234 try { 235 PARSE_MONTH = TzdbZoneRulesCompiler.class.getDeclaredMethod("parseMonth", String.class); 236 PARSE_MONTH.setAccessible(true); 237 } catch (Exception ex) { 238 throw new RuntimeException(ex); 239 } 240 } parseMonth(TzdbZoneRulesCompiler test, String str)241 private Month parseMonth(TzdbZoneRulesCompiler test, String str) throws Exception { 242 try { 243 return (Month) PARSE_MONTH.invoke(test, str); 244 } catch (InvocationTargetException ex) { 245 if (ex.getCause() != null) { 246 throw (Exception) ex.getCause(); 247 } 248 throw ex; 249 } 250 } 251 252 //----------------------------------------------------------------------- 253 // parseDayOfWeek() 254 //----------------------------------------------------------------------- 255 @Test test_parseDayOfWeek()256 public void test_parseDayOfWeek() throws Exception { 257 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 258 assertEquals(parseDayOfWeek(test, "Mon"), DayOfWeek.MONDAY); 259 assertEquals(parseDayOfWeek(test, "Tue"), DayOfWeek.TUESDAY); 260 assertEquals(parseDayOfWeek(test, "Wed"), DayOfWeek.WEDNESDAY); 261 assertEquals(parseDayOfWeek(test, "Thu"), DayOfWeek.THURSDAY); 262 assertEquals(parseDayOfWeek(test, "Fri"), DayOfWeek.FRIDAY); 263 assertEquals(parseDayOfWeek(test, "Sat"), DayOfWeek.SATURDAY); 264 assertEquals(parseDayOfWeek(test, "Sun"), DayOfWeek.SUNDAY); 265 assertEquals(parseDayOfWeek(test, "Monday"), DayOfWeek.MONDAY); 266 assertEquals(parseDayOfWeek(test, "Tuesday"), DayOfWeek.TUESDAY); 267 assertEquals(parseDayOfWeek(test, "Wednesday"), DayOfWeek.WEDNESDAY); 268 assertEquals(parseDayOfWeek(test, "Thursday"), DayOfWeek.THURSDAY); 269 assertEquals(parseDayOfWeek(test, "Friday"), DayOfWeek.FRIDAY); 270 assertEquals(parseDayOfWeek(test, "Saturday"), DayOfWeek.SATURDAY); 271 assertEquals(parseDayOfWeek(test, "Sunday"), DayOfWeek.SUNDAY); 272 assertEquals(parseDayOfWeek(test, "Mond"), DayOfWeek.MONDAY); 273 assertEquals(parseDayOfWeek(test, "Monda"), DayOfWeek.MONDAY); 274 } 275 276 @Test(expectedExceptions=IllegalArgumentException.class) test_parseDayOfWeek_invalidMonth()277 public void test_parseDayOfWeek_invalidMonth() throws Exception { 278 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 279 parseMonth(test, "ABC"); 280 } 281 282 static final Method PARSE_DOW; 283 static { 284 try { 285 PARSE_DOW = TzdbZoneRulesCompiler.class.getDeclaredMethod("parseDayOfWeek", String.class); 286 PARSE_DOW.setAccessible(true); 287 } catch (Exception ex) { 288 throw new RuntimeException(ex); 289 } 290 } parseDayOfWeek(TzdbZoneRulesCompiler test, String str)291 private DayOfWeek parseDayOfWeek(TzdbZoneRulesCompiler test, String str) throws Exception { 292 try { 293 return (DayOfWeek) PARSE_DOW.invoke(test, str); 294 } catch (InvocationTargetException ex) { 295 if (ex.getCause() != null) { 296 throw (Exception) ex.getCause(); 297 } 298 throw ex; 299 } 300 } 301 302 //----------------------------------------------------------------------- 303 // parseMonthDayTime() 304 //----------------------------------------------------------------------- 305 @Test test_parseMonthDayTime_marLastSun0220()306 public void test_parseMonthDayTime_marLastSun0220() throws Exception { 307 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 308 TZDBRule mdt = parseMonthDayTime(test, "Mar lastSun 2:20"); 309 assertEquals(mdt.month, Month.MARCH); 310 assertEquals(mdt.dayOfWeek, DayOfWeek.SUNDAY); 311 assertEquals(mdt.dayOfMonth, -1); 312 assertEquals(mdt.adjustForwards, false); 313 assertEquals(mdt.time, LocalTime.of(2, 20)); 314 assertEquals(mdt.adjustDays, 0); 315 assertEquals(mdt.timeDefinition, TimeDefinition.WALL); 316 } 317 318 @Test test_parseMonthDayTime_jun50220s()319 public void test_parseMonthDayTime_jun50220s() throws Exception { 320 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 321 TZDBRule mdt = parseMonthDayTime(test, "Jun 5 2:20s"); 322 assertEquals(mdt.month, Month.JUNE); 323 assertEquals(mdt.dayOfWeek, null); 324 assertEquals(mdt.dayOfMonth, 5); 325 assertEquals(mdt.adjustForwards, true); 326 assertEquals(mdt.time, LocalTime.of(2, 20)); 327 assertEquals(mdt.adjustDays, 0); 328 assertEquals(mdt.timeDefinition, TimeDefinition.STANDARD); 329 } 330 331 @Test test_parseMonthDayTime_maySatAfter50220u()332 public void test_parseMonthDayTime_maySatAfter50220u() throws Exception { 333 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 334 TZDBRule mdt = parseMonthDayTime(test, "May Sat>=5 2:20u"); 335 assertEquals(mdt.month, Month.MAY); 336 assertEquals(mdt.dayOfWeek, DayOfWeek.SATURDAY); 337 assertEquals(mdt.dayOfMonth, 5); 338 assertEquals(mdt.adjustForwards, true); 339 assertEquals(mdt.time, LocalTime.of(2, 20)); 340 assertEquals(mdt.adjustDays, 0); 341 assertEquals(mdt.timeDefinition, TimeDefinition.UTC); 342 } 343 344 @Test test_parseMonthDayTime_maySatBefore50220u()345 public void test_parseMonthDayTime_maySatBefore50220u() throws Exception { 346 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 347 TZDBRule mdt = parseMonthDayTime(test, "May Sat<=5 24:00g"); 348 assertEquals(mdt.month, Month.MAY); 349 assertEquals(mdt.dayOfWeek, DayOfWeek.SATURDAY); 350 assertEquals(mdt.dayOfMonth, 5); 351 assertEquals(mdt.adjustForwards, false); 352 assertEquals(mdt.time, LocalTime.of(0, 0)); 353 assertEquals(mdt.adjustDays, 1); 354 assertEquals(mdt.timeDefinition, TimeDefinition.UTC); 355 } 356 357 @Test test_parseMonthDayTime_maySatBefore15Dash()358 public void test_parseMonthDayTime_maySatBefore15Dash() throws Exception { 359 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 360 TZDBRule mdt = parseMonthDayTime(test, "May Sat<=15 -"); 361 assertEquals(mdt.month, Month.MAY); 362 assertEquals(mdt.dayOfWeek, DayOfWeek.SATURDAY); 363 assertEquals(mdt.dayOfMonth, 15); 364 assertEquals(mdt.adjustForwards, false); 365 assertEquals(mdt.time, LocalTime.of(0, 0)); 366 assertEquals(mdt.adjustDays, 0); 367 assertEquals(mdt.timeDefinition, TimeDefinition.WALL); 368 } 369 370 @Test test_parseMonthDayTime_maylastSunShortTime()371 public void test_parseMonthDayTime_maylastSunShortTime() throws Exception { 372 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 373 TZDBRule mdt = parseMonthDayTime(test, "May lastSun 3z"); 374 assertEquals(mdt.month, Month.MAY); 375 assertEquals(mdt.dayOfWeek, DayOfWeek.SUNDAY); 376 assertEquals(mdt.dayOfMonth, -1); 377 assertEquals(mdt.adjustForwards, false); 378 assertEquals(mdt.time, LocalTime.of(3, 0)); 379 assertEquals(mdt.adjustDays, 0); 380 assertEquals(mdt.timeDefinition, TimeDefinition.UTC); 381 } 382 383 @Test test_parseMonthDayTime_sepSatAfter82500()384 public void test_parseMonthDayTime_sepSatAfter82500() throws Exception { 385 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2018f", new ArrayList<File>(), null, false); 386 TZDBRule mdt = parseMonthDayTime(test, "Sep Sat>=8 25:00"); 387 assertEquals(mdt.month, Month.SEPTEMBER); 388 assertEquals(mdt.dayOfWeek, DayOfWeek.SATURDAY); 389 assertEquals(mdt.dayOfMonth, 8); 390 assertEquals(mdt.adjustForwards, true); 391 assertEquals(mdt.time, LocalTime.of(1, 0)); 392 assertEquals(mdt.adjustDays, 1); 393 assertEquals(mdt.timeDefinition, TimeDefinition.WALL); 394 } 395 396 static final Method PARSE_MDT; 397 static { 398 try { 399 PARSE_MDT = TzdbZoneRulesCompiler.class.getDeclaredMethod("parseMonthDayTime", StringTokenizer.class, TZDBMonthDayTime.class); 400 PARSE_MDT.setAccessible(true); 401 } catch (Exception ex) { 402 throw new RuntimeException(ex); 403 } 404 } parseMonthDayTime(TzdbZoneRulesCompiler test, String str)405 private TZDBRule parseMonthDayTime(TzdbZoneRulesCompiler test, String str) throws Exception { 406 try { 407 TZDBRule mdt = test.new TZDBRule(); // create a bound inner class 408 PARSE_MDT.invoke(test, new StringTokenizer(str), mdt); 409 return mdt; 410 } catch (InvocationTargetException ex) { 411 if (ex.getCause() != null) { 412 throw (Exception) ex.getCause(); 413 } 414 throw ex; 415 } 416 } 417 418 //----------------------------------------------------------------------- 419 @Test test_parseLeapSecondRule_at_midnight()420 public void test_parseLeapSecondRule_at_midnight() throws Exception { 421 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 422 LeapSecondRule lsr = parseLeapSecondRule(test, "Leap\t1972 Jun\t30 23:59:60 + S"); 423 assertEquals(lsr.leapDate, LocalDate.of(1972, Month.JUNE, 30)); 424 assertEquals(lsr.secondAdjustment, +1); 425 } 426 427 @Test test_parseLeapSecondRule_just_before_midnight()428 public void test_parseLeapSecondRule_just_before_midnight() throws Exception { 429 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 430 LeapSecondRule lsr = parseLeapSecondRule(test, "Leap\t2009 May\t1 23:59:59 - S"); 431 assertEquals(lsr.leapDate, LocalDate.of(2009, Month.MAY, 1)); 432 assertEquals(lsr.secondAdjustment, -1); 433 } 434 435 @Test(expectedExceptions=IllegalArgumentException.class) test_parseLeapSecondRule_too_short()436 public void test_parseLeapSecondRule_too_short() throws Exception { 437 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 438 parseLeapSecondRule(test, "Leap\t2009 May\t1 23:59:60 S"); 439 } 440 441 @Test(expectedExceptions=IllegalArgumentException.class) test_parseLeapSecondRule_bad_adjustment()442 public void test_parseLeapSecondRule_bad_adjustment() throws Exception { 443 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 444 parseLeapSecondRule(test, "Leap\t2009 May\t1 23:59:60 % S"); 445 } 446 447 @Test(expectedExceptions=IllegalArgumentException.class) test_parseLeapSecondRule_rolling()448 public void test_parseLeapSecondRule_rolling() throws Exception { 449 TzdbZoneRulesCompiler test = new TzdbZoneRulesCompiler("2010c", new ArrayList<File>(), null, false); 450 parseLeapSecondRule(test, "Leap\t2009 May\t1 23:59:60 - R"); 451 } 452 453 static final Method PARSE_LSR; 454 static { 455 try { 456 PARSE_LSR = TzdbZoneRulesCompiler.class.getDeclaredMethod("parseLeapSecondRule", String.class); 457 PARSE_LSR.setAccessible(true); 458 } catch (Exception ex) { 459 throw new RuntimeException(ex); 460 } 461 } parseLeapSecondRule(TzdbZoneRulesCompiler test, String str)462 private LeapSecondRule parseLeapSecondRule(TzdbZoneRulesCompiler test, String str) throws Exception { 463 try { 464 return (LeapSecondRule)PARSE_LSR.invoke(test, str); 465 } catch (InvocationTargetException ex) { 466 if (ex.getCause() != null) { 467 throw (Exception) ex.getCause(); 468 } 469 throw ex; 470 } 471 } 472 473 } 474