CompositeDelayParser implements DelayParser { @Override public Duration parse(final String value) { final Duration delay = parsers.stream() .map(parser -> parser.parse(value)) .filter(Objects::nonNull) .findFirst() .orElse(null); if (delay == null) { log.warn("Received unsupported 'Retry-After' header [{}]; will ignore it", value); } return delay; }  @Override Duration parse(final String value);  }
@Test void shouldUseFirstNonNullDelay() { when(first.parse("1")).thenReturn(Duration.ofSeconds(1)); when(second.parse("2")).thenReturn(Duration.ofSeconds(2)); assertEquals(Duration.ofSeconds(1), unit.parse("1")); }
@Test void shouldIgnoreNullDelay() { when(second.parse("2")).thenReturn(Duration.ofSeconds(2)); assertEquals(Duration.ofSeconds(2), unit.parse("2")); }
@Test void shouldFallbackToNullDelay() { when(first.parse("1")).thenReturn(Duration.ofSeconds(1)); when(second.parse("2")).thenReturn(Duration.ofSeconds(2)); assertNull(unit.parse("3")); }