DittoDuration implements CharSequence { static DittoDuration parseDuration(final CharSequence duration) { return parseDuration(checkNotNull(duration, "duration"), DittoTimeUnit.values()); } private  DittoDuration(final long amount, final DittoTimeUnit dittoTimeUnit); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); @Override String toString(); @Override boolean equals(@Nullable final Object o); @Override int hashCode();  }
@Test public void createDittoDurationFromStringHoursFails() { assertThatExceptionOfType(NumberFormatException.class) .isThrownBy(() -> DittoDuration.parseDuration("1h")); }
@Test public void tryToParseEmptyString() { assertThatExceptionOfType(NumberFormatException.class) .isThrownBy(() -> DittoDuration.parseDuration("")) .withMessageContaining("\"\"") .withNoCause(); }
@Test public void tryToParseDurationWithNegativeAmountAndSuffix() { final String durationString = "-15s"; assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> DittoDuration.parseDuration(durationString)) .withMessage("The duration must not be negative but was <%s>!", durationString) .withNoCause(); }
@Test public void tryToParseDurationWithNegativeAmountWithoutSuffix() { final String durationString = "-15"; assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> DittoDuration.parseDuration(durationString)) .withMessage("The duration must not be negative but was <%s>!", durationString) .withNoCause(); }