DurationParser { public static Duration parse(String rawString) throws NumberFormatException { return parse(rawString, ChronoUnit.MILLIS); } private  DurationParser(); static Duration parse(String rawString); static Duration parse(String rawString, ChronoUnit defaultUnit);  }
@Test void parseShouldUseMsAsDefaultUnit() { assertThat(DurationParser.parse("2")) .isEqualTo(Duration.ofMillis(2)); }
@Test void parseShouldUseSpecifiedDefaultUnit() { assertThat(DurationParser.parse("2", ChronoUnit.SECONDS)) .isEqualTo(Duration.ofSeconds(2)); }
@Test void parseShouldUseSpecifiedUnit() { assertThat(DurationParser.parse("2 minutes", ChronoUnit.SECONDS)) .isEqualTo(Duration.ofMinutes(2)); }
@Test void parseShouldSupportStartingSpaces() { assertThat(DurationParser.parse(" 2 minutes")) .isEqualTo(Duration.ofMinutes(2)); }
@Test void parseShouldSupportEndingSpaces() { assertThat(DurationParser.parse("2 minutes ")) .isEqualTo(Duration.ofMinutes(2)); }
@Test void parseShouldThrowOnNegativeValue() { assertThatThrownBy(() -> DurationParser.parse("-2 minutes")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Duration amount should be positive"); }
@Test void parseShouldThrowWhenIllegalUnitInRawString() { assertThatThrownBy(() -> DurationParser.parse("2 unknown")) .isInstanceOf(NumberFormatException.class); }
@Test void parseShouldThrowWhenMissingAmount() { assertThatThrownBy(() -> DurationParser.parse("seconds")) .isInstanceOf(NumberFormatException.class); }
@Test void parseShouldThrowWhenMissingAmountWithExtraWhiteSpace() { assertThatThrownBy(() -> DurationParser.parse(" seconds")) .isInstanceOf(NumberFormatException.class); }
@Test void parseShouldThrowWhenEmpty() { assertThatThrownBy(() -> DurationParser.parse("")) .isInstanceOf(NumberFormatException.class); }
@Test void parseShouldThrowWhenZero() { assertThat(DurationParser.parse("0 s")) .isEqualTo(Duration.ofSeconds(0)); }
@Test void parseShouldThrowWhenIllegalPattern() { assertThatThrownBy(() -> DurationParser.parse("illegal pattern")) .isInstanceOf(NumberFormatException.class); }