Interval implements TemporalAmount { @Override public long get(final TemporalUnit unit) { if (unit == ChronoUnit.SECONDS || unit == ChronoUnit.NANOS) { return duration.get(unit); } return period.get(unit); } Interval(final Period period, final Duration duration);  Interval(final Duration duration);  Interval(final Period period); Period getPeriod(); Duration getDuration(); long toEpochMilli(final long fromEpochMilli); @Override long get(final TemporalUnit unit); @Override List<TemporalUnit> getUnits(); @Override Temporal addTo(final Temporal temporal); @Override Temporal subtractFrom(final Temporal temporal); @Override int hashCode(); @Override boolean equals(final Object o); @Override String toString(); static Interval parse(final String text);  }
@Test public void shouldThrowExceptionOnGetUnsupportedTemporalUnit() { final Interval interval = new Interval(Period.of(1, 2, 3), Duration.ofSeconds(5, 35)); final List<ChronoUnit> supportedUnits = Arrays.asList( ChronoUnit.SECONDS, ChronoUnit.NANOS, ChronoUnit.DAYS, ChronoUnit.MONTHS, ChronoUnit.YEARS); final List<ChronoUnit> unsupportedUnits = Arrays.stream(ChronoUnit.values()) .filter(unit -> !supportedUnits.contains(unit)) .collect(Collectors.toList()); for (final ChronoUnit unit : unsupportedUnits) { assertThatThrownBy(() -> interval.get(unit)) .isInstanceOf(UnsupportedTemporalTypeException.class); } }