2416 } 2417 2418 @Test(expectedExceptions=NullPointerException.class) 2419 public void test_atOffset_nullZoneOffset() { 2420 LocalTime t = LocalTime.of(11, 30); 2421 t.atOffset((ZoneOffset) null); 2422 } 2423 2424 //----------------------------------------------------------------------- 2425 // toSecondOfDay() 2426 //----------------------------------------------------------------------- 2427 @Test 2428 public void test_toSecondOfDay() { 2429 LocalTime t = LocalTime.of(0, 0); 2430 for (int i = 0; i < 24 * 60 * 60; i++) { 2431 assertEquals(t.toSecondOfDay(), i); 2432 t = t.plusSeconds(1); 2433 } 2434 } 2435 2436 @Test 2437 public void test_toSecondOfDay_fromNanoOfDay_symmetry() { 2438 LocalTime t = LocalTime.of(0, 0); 2439 for (int i = 0; i < 24 * 60 * 60; i++) { 2440 assertEquals(LocalTime.ofSecondOfDay(t.toSecondOfDay()), t); 2441 t = t.plusSeconds(1); 2442 } 2443 } 2444 2445 //----------------------------------------------------------------------- 2446 // toNanoOfDay() 2447 //----------------------------------------------------------------------- 2448 @Test 2449 public void test_toNanoOfDay() { 2450 LocalTime t = LocalTime.of(0, 0); 2451 for (int i = 0; i < 1000000; i++) { 2452 assertEquals(t.toNanoOfDay(), i); 2453 t = t.plusNanos(1); 2454 } 2455 t = LocalTime.of(0, 0); | 2416 } 2417 2418 @Test(expectedExceptions=NullPointerException.class) 2419 public void test_atOffset_nullZoneOffset() { 2420 LocalTime t = LocalTime.of(11, 30); 2421 t.atOffset((ZoneOffset) null); 2422 } 2423 2424 //----------------------------------------------------------------------- 2425 // toSecondOfDay() 2426 //----------------------------------------------------------------------- 2427 @Test 2428 public void test_toSecondOfDay() { 2429 LocalTime t = LocalTime.of(0, 0); 2430 for (int i = 0; i < 24 * 60 * 60; i++) { 2431 assertEquals(t.toSecondOfDay(), i); 2432 t = t.plusSeconds(1); 2433 } 2434 } 2435 2436 //----------------------------------------------------------------------- 2437 // toEpochSecond() 2438 //-------------------------------------------------------------------------- 2439 @DataProvider(name="epochSecond") 2440 Object[][] provider__toEpochSecond() { 2441 return new Object[][] { 2442 {LocalTime.of(0, 0).toEpochSecond(OFFSET_PTWO), -7200}, 2443 {LocalTime.of(11, 30).toEpochSecond(OFFSET_PTWO), 34200}, 2444 {LocalTime.of(0, 0).toEpochSecond(OFFSET_PTWO), 2445 Instant.ofEpochSecond(-7200).getEpochSecond()}, 2446 {LocalTime.of(11, 30).toEpochSecond(OFFSET_PTWO), 2447 Instant.ofEpochSecond(34200).getEpochSecond()}, 2448 {LocalTime.of(11, 30).toEpochSecond(OFFSET_PTWO), 2449 LocalDateTime.of(1970, 1, 1, 11, 30).toEpochSecond(OFFSET_PTWO)}, 2450 }; 2451 } 2452 2453 @Test(dataProvider="epochSecond") 2454 public void test_toEpochSecond(long actual, long expected) { 2455 assertEquals(actual, expected); 2456 } 2457 2458 //----------------------------------------------------------------------- 2459 // toSecondOfDay_fromNanoOfDay_symmetry() 2460 //----------------------------------------------------------------------- 2461 @Test 2462 public void test_toSecondOfDay_fromNanoOfDay_symmetry() { 2463 LocalTime t = LocalTime.of(0, 0); 2464 for (int i = 0; i < 24 * 60 * 60; i++) { 2465 assertEquals(LocalTime.ofSecondOfDay(t.toSecondOfDay()), t); 2466 t = t.plusSeconds(1); 2467 } 2468 } 2469 2470 //----------------------------------------------------------------------- 2471 // toNanoOfDay() 2472 //----------------------------------------------------------------------- 2473 @Test 2474 public void test_toNanoOfDay() { 2475 LocalTime t = LocalTime.of(0, 0); 2476 for (int i = 0; i < 1000000; i++) { 2477 assertEquals(t.toNanoOfDay(), i); 2478 t = t.plusNanos(1); 2479 } 2480 t = LocalTime.of(0, 0); |