@Override
    public Duration convert(String source) {
        try {
            if (ISO8601.matcher(source).matches()) {
                return Duration.parse(source);
            }
            Matcher matcher = SIMPLE.matcher(source);
            Assert.state(matcher.matches(), "'" + source + "' is not a valid duration");
            long amount = Long.parseLong(matcher.group(1));
            ChronoUnit unit = getUnit(matcher.group(2));
            return Duration.of(amount, unit);
        } catch (Exception ex) {
            throw new IllegalStateException("'" + source + "' is not a valid duration", ex);
        }
    }
@Test
    public void convertWhenBadFormatShouldThrowException() {
        assertThatExceptionOfType(IllegalStateException.class)
                .isThrownBy(() -> convert("10foo"))
                .withMessageContaining("'10foo' is not a valid duration");
    }