Delays { public static long compareTimeAndDelay(TimeDelay startInclusive, TimeDelay endExclusive) { long result; if (startInclusive == endExclusive) { result = 0; } else if (startInclusive != null && endExclusive != null) { LocalTime start = startInclusive.getEffectiveTime(); LocalTime end = endExclusive.getEffectiveTime(); Duration duration = Duration.between(start, end); result = -duration.toMillis(); } else if (startInclusive != null) { result = 1; } else { result = -1; } 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 public void testCompareTimeAndDelay() throws Exception { LocalTime departureA = LocalTime.now(); TimeDelay departureB = TimeDelay.of(departureA, 0L); Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(equalTo(0L))); }
@Test public void testCompareTimeAndDelayWithLeftIsNull() throws Exception { TimeDelay departureA = null; TimeDelay departureB = TimeDelay.now(); Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(lessThan(0L))); }
@Test public void testCompareTimeAndDelayWithRightIsNull() throws Exception { TimeDelay departureA = TimeDelay.now(); TimeDelay departureB = null; Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(greaterThan(0L))); }
@Test public void testCompareTimeAndDelayEquals() throws Exception { LocalTime departureA = LocalTime.parse("15:05"); TimeDelay departureB = TimeDelay.of(LocalTime.parse("15:00"), 5L, ChronoUnit.MINUTES); Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(equalTo(0L))); }
@Test public void testRevertedCompareTimeAndDelayEquals() throws Exception { LocalTime departureA = LocalTime.parse("15:05"); TimeDelay departureB = TimeDelay.of(LocalTime.parse("15:00"), 5L, ChronoUnit.MINUTES); Assert.assertThat(Delays.compareTimeAndDelay(departureB, departureA), is(equalTo(0L))); }
@Test public void testCompareTimeAndNullDelay() throws Exception { LocalTime departureA = LocalTime.now(); TimeDelay departureB = TimeDelay.of(departureA, null); Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(equalTo(0L))); }
@Test public void testCompareNullTimeAndDelay() throws Exception { LocalTime departureA = LocalTime.now(); TimeDelay departureB = TimeDelay.of(null, 5L); Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(greaterThan(0L))); }
@Test public void testCompareTimeAndDelayGreater() throws Exception { LocalTime departureA = LocalTime.parse("15:00"); TimeDelay departureB = TimeDelay.of(LocalTime.parse("14:00"), 0L); Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(greaterThan(0L))); }
@Test public void testCompareTimeAndDelayLess() throws Exception { LocalTime departureA = LocalTime.parse("15:00"); TimeDelay departureB = TimeDelay.of(departureA, 5L); Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(lessThan(0L))); }
@Test public void testCompareTimeWithoutDelaysEquals() throws Exception { LocalTime departureA = LocalTime.parse("15:05"); TimeDelay departureB = TimeDelay.of(LocalTime.parse("15:00"), 5L * 60 * 1000); Assert.assertThat(Delays.compareTimeAndDelay(departureA, departureB), is(equalTo(0L))); }