467 468 @Test(dataProvider="offsetPatterns") 469 public void test_appendOffset_parse(String pattern, int h, int m, int s, String expected) throws Exception { 470 builder.appendOffset(pattern, "Z"); 471 DateTimeFormatter f = builder.toFormatter(); 472 ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(h, m, s); 473 ZoneOffset parsed = f.parse(expected, ZoneOffset::from); 474 assertEquals(f.format(parsed), expected); 475 } 476 477 @DataProvider(name="badOffsetPatterns") 478 Object[][] data_badOffsetPatterns() { 479 return new Object[][] { 480 {"HH"}, 481 {"HHMM"}, 482 {"HH:MM"}, 483 {"HHMMss"}, 484 {"HH:MM:ss"}, 485 {"HHMMSS"}, 486 {"HH:MM:SS"}, 487 {"+H"}, 488 {"+HMM"}, 489 {"+HHM"}, 490 {"+A"}, 491 }; 492 } 493 494 @Test(dataProvider="badOffsetPatterns", expectedExceptions=IllegalArgumentException.class) 495 public void test_appendOffset_badPattern(String pattern) throws Exception { 496 builder.appendOffset(pattern, "Z"); 497 } 498 499 @Test(expectedExceptions=NullPointerException.class) 500 public void test_appendOffset_3arg_nullText() throws Exception { 501 builder.appendOffset("+HH:MM", null); 502 } 503 504 @Test(expectedExceptions=NullPointerException.class) 505 public void test_appendOffset_3arg_nullPattern() throws Exception { 506 builder.appendOffset(null, "Z"); 507 } 508 | 467 468 @Test(dataProvider="offsetPatterns") 469 public void test_appendOffset_parse(String pattern, int h, int m, int s, String expected) throws Exception { 470 builder.appendOffset(pattern, "Z"); 471 DateTimeFormatter f = builder.toFormatter(); 472 ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(h, m, s); 473 ZoneOffset parsed = f.parse(expected, ZoneOffset::from); 474 assertEquals(f.format(parsed), expected); 475 } 476 477 @DataProvider(name="badOffsetPatterns") 478 Object[][] data_badOffsetPatterns() { 479 return new Object[][] { 480 {"HH"}, 481 {"HHMM"}, 482 {"HH:MM"}, 483 {"HHMMss"}, 484 {"HH:MM:ss"}, 485 {"HHMMSS"}, 486 {"HH:MM:SS"}, 487 {"+HHM"}, 488 {"+A"}, 489 }; 490 } 491 492 @Test(dataProvider="badOffsetPatterns", expectedExceptions=IllegalArgumentException.class) 493 public void test_appendOffset_badPattern(String pattern) throws Exception { 494 builder.appendOffset(pattern, "Z"); 495 } 496 497 @Test(expectedExceptions=NullPointerException.class) 498 public void test_appendOffset_3arg_nullText() throws Exception { 499 builder.appendOffset("+HH:MM", null); 500 } 501 502 @Test(expectedExceptions=NullPointerException.class) 503 public void test_appendOffset_3arg_nullPattern() throws Exception { 504 builder.appendOffset(null, "Z"); 505 } 506 |