Delays { public static LocalTime toLocalTime(Date date) { LocalTime result; if (date instanceof java.sql.Time) { result = ((java.sql.Time) date).toLocalTime(); } else if (date instanceof java.sql.Date) { throw new UnsupportedOperationException("Cannot handle java.sql.Date because we expect only a time"); } else if (date instanceof java.sql.Timestamp) { result = ((java.sql.Timestamp) date) .toLocalDateTime() .toLocalTime(); } else { result = LocalDateTime .ofInstant(date.toInstant(), ZoneId.systemDefault()) .toLocalTime(); } return result; }  static long compareTimeAndDelay(TimeDelay startInclusive, TimeDelay endExclusive); static long compareTimeAndDelay(LocalTime time, TimeDelay timeDelay); static long compareTimeAndDelay(TimeDelay timeDelay, LocalTime time); static long compareTime(TimeDelay timeDelayA, TimeDelay timeDelayB); static long compareTime(TimeDelay timeDelay, LocalTime time); static long compareTime(LocalTime time, TimeDelay timeDelay); static long compareTime(LocalTime timeA, LocalTime timeB); static long computeDelay(LocalTime expectedTime, LocalTime effectiveTime); static LocalTime toLocalTime(Date date); static Long toMinutes(Long delay); static Long toMillis(Long delay); static final LocalDate DATE; }
@Test(expected = UnsupportedOperationException.class) public void testToLocalTimeWithSqlDate() { Delays.toLocalTime(Date.valueOf("2000-01-01")); }
@Test public void testToLocalTimeWithSqlTime() { Assert.assertEquals(LocalTime.of(12, 0, 0), Delays.toLocalTime(Time.valueOf("12:00:00"))); }
@Test public void testToLocalTimeWithSqlTimestamp() { Assert.assertEquals(LocalTime.of(12, 0, 0), Delays.toLocalTime(Timestamp.valueOf("2000-01-01 12:00:00"))); }
@Test public void testToLocalTimeWithUtilDate() throws ParseException { Assert.assertEquals(LocalTime.of(12, 0, 0), Delays.toLocalTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2000-01-01 12:00:00"))); }