### Question:
TemporalAmountAdapter implements Function<TemporalAmount, TemporalAmount> { @Override public TemporalAmount apply(TemporalAmount internalTemporalAmountRepresentation) { int[] values = new int[SUPPORTED_UNITS.length]; int type = 0; for (int i = 0; i < SUPPORTED_UNITS.length; ++i) { values[i] = TEMPORAL_UNIT_EXTRACTOR.apply(internalTemporalAmountRepresentation, SUPPORTED_UNITS[i]); type |= (values[i] == 0) ? 0 : (0b10000 >> i); } boolean couldBePeriod = couldBePeriod(type); boolean couldBeDuration = couldBeDuration(type); if (couldBePeriod && !couldBeDuration) { return Period.of(values[FIELD_YEAR], values[FIELD_MONTH], values[FIELD_DAY]).normalized(); } else if (couldBeDuration && !couldBePeriod) { return Duration.ofSeconds(values[FIELD_SECONDS]).plusNanos(values[FIELD_NANOS]); } else { return internalTemporalAmountRepresentation; } }  @Override TemporalAmount apply(TemporalAmount internalTemporalAmountRepresentation);  }### Answer:
@Test public void internallyCreatedTypesShouldBeConvertedCorrect() { final TemporalAmountAdapter adapter = new TemporalAmountAdapter(); assertThat(adapter.apply(Values.isoDuration(1, 0, 0, 0).asIsoDuration())).isEqualTo(Period.ofMonths(1)); assertThat(adapter.apply(Values.isoDuration(1, 1, 0, 0).asIsoDuration())) .isEqualTo(Period.ofMonths(1).plusDays(1)); assertThat(adapter.apply(Values.isoDuration(1, 1, 1, 0).asIsoDuration())) .isEqualTo(Values.isoDuration(1, 1, 1, 0).asIsoDuration()); assertThat(adapter.apply(Values.isoDuration(0, 0, 120, 1).asIsoDuration())) .isEqualTo(Duration.ofMinutes(2).plusNanos(1)); }
@Test public void durationsShouldStayDurations() { final TemporalAmountAdapter adapter = new TemporalAmountAdapter(); Duration duration = MONTHS.getDuration().multipliedBy(13).plus(DAYS.getDuration().multipliedBy(32)).plusHours(25) .plusMinutes(120); assertThat(adapter.apply(Values.value(duration).asIsoDuration())).isEqualTo(duration); }
@Test public void periodsShouldStayPeriods() { final TemporalAmountAdapter adapter = new TemporalAmountAdapter(); Period period = Period.between(LocalDate.of(2018, 11, 15), LocalDate.of(2020, 12, 24)); assertThat(adapter.apply(Values.value(period).asIsoDuration())).isEqualTo(period.normalized()); }