DittoDuration implements CharSequence { static DittoDuration of(final Duration duration) { checkNotNull(duration, "duration"); checkArgument(duration, d -> !d.isNegative(), () -> MessageFormat.format("The duration must not be negative but was <{0}>!", duration)); return new DittoDuration(duration.toMillis(), DittoTimeUnit.MILLISECONDS); } 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 tryToGetInstanceFromNullDuration() { assertThatNullPointerException() .isThrownBy(() -> DittoDuration.of(null)) .withMessage("The duration must not be null!") .withNoCause(); }
@Test public void tryToGetInstanceFromNegativeDuration() { final Duration javaDuration = Duration.ofSeconds(-5); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> DittoDuration.of(javaDuration)) .withMessage("The duration must not be negative but was <%s>!", javaDuration) .withNoCause(); }