Polish "Reject empty strings in DurationFormatterUtils"

See gh-33669
This commit is contained in:
Stéphane Nicoll
2024-10-09 15:20:28 +02:00
parent 02c990ca82
commit e2238c0211
2 changed files with 16 additions and 26 deletions

View File

@@ -41,6 +41,22 @@ import static org.springframework.format.annotation.DurationFormat.Style.SIMPLE;
*/
class DurationFormatterUtilsTests {
@ParameterizedTest
@EnumSource(DurationFormat.Style.class)
void parseEmptyStringFailsWithDedicatedException(DurationFormat.Style style) {
assertThatIllegalArgumentException()
.isThrownBy(() -> DurationFormatterUtils.parse("", style))
.withMessage("Value must not be empty");
}
@ParameterizedTest
@EnumSource(DurationFormat.Style.class)
void parseNullStringFailsWithDedicatedException(DurationFormat.Style style) {
assertThatIllegalArgumentException()
.isThrownBy(() -> DurationFormatterUtils.parse(null, style))
.withMessage("Value must not be empty");
}
@Test
void parseSimpleWithUnits() {
Duration nanos = DurationFormatterUtils.parse("1ns", SIMPLE, Unit.SECONDS);
@@ -191,22 +207,6 @@ class DurationFormatterUtilsTests {
.havingCause().withMessage("Does not match composite duration pattern");
}
@ParameterizedTest
@EnumSource(DurationFormat.Style.class)
void parseEmptyStringThrowsForAllStyles(DurationFormat.Style style) {
assertThatIllegalArgumentException()
.isThrownBy(() -> DurationFormatterUtils.parse("", style))
.withMessage("Value must not be empty");
}
@ParameterizedTest
@EnumSource(DurationFormat.Style.class)
void parseNullStringThrowsForAllStyles(DurationFormat.Style style) {
assertThatIllegalArgumentException()
.isThrownBy(() -> DurationFormatterUtils.parse(null, style))
.withMessage("Value must not be empty");
}
@Test
void printSimple() {
assertThat(DurationFormatterUtils.print(Duration.ofNanos(12345), SIMPLE, Unit.NANOS))
@@ -259,14 +259,6 @@ class DurationFormatterUtilsTests {
.isEqualTo("-1d2h34m57s28ms3us2ns");
}
@ParameterizedTest
@EnumSource(DurationFormat.Style.class)
void printNullDurationThrowsForAllStyles(DurationFormat.Style style) {
assertThatIllegalArgumentException()
.isThrownBy(() -> DurationFormatterUtils.print(null, style))
.withMessage("Value must not be null");
}
@Test
void detectAndParse() {
assertThat(DurationFormatterUtils.detectAndParse("PT1.234S", Unit.NANOS))