### Question:
TimeGranularity implements Granularity<LocalTime> { @Override public LocalTime getNext(LocalTime value, int amount) { value = value.truncatedTo(granularity); return value.plus(granularity.getDuration().multipliedBy(amount)); } TimeGranularity(ChronoUnit granularity); static TimeGranularity create(String granularity); @Override Granularity<LocalTime> getFinestGranularity(); @Override boolean isCorrectScale(LocalTime value); @Override Granularity<LocalTime> merge(Granularity<LocalTime> otherGranularity); @Override LocalTime getNext(LocalTime value, int amount); @Override LocalTime getNext(LocalTime value); @Override LocalTime getPrevious(LocalTime value, int amount); @Override LocalTime getPrevious(LocalTime value); @Override LocalTime trimToGranularity(LocalTime value); @Override LocalTime getRandom(LocalTime min, LocalTime max, RandomNumberGenerator randomNumberGenerator); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final TimeGranularity DEFAULT; }### Answer:
@Test void getNext_returnsMidnight_WhenPassedTimeNearMidnight() { TimeGranularity granularity = new TimeGranularity(ChronoUnit.SECONDS); LocalTime time = LocalTime.of(23, 59, 59, 234); LocalTime expected = Defaults.TIME_MAX; Assert.assertEquals(expected, granularity.getNext(time)); }
@Test void getNextMultiple_returnsAfterMidnight_WhenPassedTimeNearMidnight() { TimeGranularity granularity = new TimeGranularity(ChronoUnit.SECONDS); LocalTime time = LocalTime.of(23, 59, 59, 234); LocalTime expected = LocalTime.of(0, 0, 29); Assert.assertEquals(expected, granularity.getNext(time, 30)); }
@Test void getNext_returnsNextValidValue_whenPassedValueAtGranularity() { TimeGranularity granularity = new TimeGranularity(ChronoUnit.HOURS); LocalTime time = LocalTime.of(1, 0); LocalTime expected = LocalTime.of(2, 0); Assert.assertEquals(expected, granularity.getNext(time)); }
@Test void getNext_returnsNextValidValue_whenPassedValueBetweenGranularity() { TimeGranularity granularity = new TimeGranularity(ChronoUnit.MINUTES); LocalTime time = LocalTime.of(1, 14, 50); LocalTime expected = LocalTime.of(1, 15, 0); Assert.assertEquals(expected, granularity.getNext(time)); }