RepeatingInterval implements Timer { public static RepeatingInterval parse(final String text) { return parse(text, INTERVAL_DESGINATOR); } RepeatingInterval(final int repetitions, final Interval interval); @Override Interval getInterval(); @Override int getRepetitions(); @Override long getDueDate(final long fromEpochMillis); @Override int hashCode(); @Override boolean equals(final Object o); static RepeatingInterval parse(final String text); static RepeatingInterval parse(final String text, final String intervalDesignator); static final String INTERVAL_DESGINATOR; static final int INFINITE; }
@Test public void shouldFailToParseIfStartingWithIntervalDesignator() { final String text = "/P1Y2M3S"; assertThatThrownBy(() -> RepeatingInterval.parse(text)) .isInstanceOf(DateTimeParseException.class); }
@Test public void shouldFailToParseIfIntervalCannotBeParsed() { final String text = "R/PKF,!T2.:"; assertThatThrownBy(() -> RepeatingInterval.parse(text)) .isInstanceOf(DateTimeParseException.class); }
@Test public void shouldFailToParseIfNoRepetitionSpecified() { final String text = "PT05S"; assertThatThrownBy(() -> RepeatingInterval.parse(text)) .isInstanceOf(DateTimeParseException.class); }
@Test public void shouldFailToParseWithoutSpecs() { final String text = "/"; assertThatThrownBy(() -> RepeatingInterval.parse(text)) .isInstanceOf(DateTimeParseException.class); }
@Test public void shouldBeInfiniteIfNoRepetitionsCountSpecified() { final String text = "R/PT05S"; final RepeatingInterval expected = new RepeatingInterval( RepeatingInterval.INFINITE, new Interval(Period.ZERO, Duration.ofSeconds(5))); final RepeatingInterval parsed = RepeatingInterval.parse(text); assertThat(parsed).isEqualTo(expected); }
@Test public void shouldHaveSpecifiedRepetitionsCount() { final String text = "R5/PT05S"; final RepeatingInterval expected = new RepeatingInterval(5, new Interval(Period.ZERO, Duration.ofSeconds(5))); final RepeatingInterval parsed = RepeatingInterval.parse(text); assertThat(parsed).isEqualTo(expected); }
@Test public void shouldFailToParseIfCannotParseRepetitionsCount() { final String text = "RA,/PT05S"; assertThatThrownBy(() -> RepeatingInterval.parse(text)) .isInstanceOf(DateTimeParseException.class); }
@Test public void shouldFailToParseIfNoInterval() { final String text = "R5/"; assertThatThrownBy(() -> RepeatingInterval.parse(text)) .isInstanceOf(DateTimeParseException.class); }
@Test public void shouldFailToParseIfRepetitionCountDoesNotStartWithR() { final String text = "B5/PT1S"; assertThatThrownBy(() -> RepeatingInterval.parse(text)) .isInstanceOf(DateTimeParseException.class); }
@Test public void shouldFailToParseEmptyString() { assertThatThrownBy(() -> Interval.parse("")).isInstanceOf(DateTimeParseException.class); }