diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatterUtils.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatterUtils.java index 34372fe9af7..b1f5f3e58bd 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatterUtils.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatterUtils.java @@ -35,7 +35,6 @@ import org.springframework.util.StringUtils; * @author Phillip Webb * @author Valentine Wu * @author Simon Baslé - * @author Kim Seungrae * @since 6.2 */ public abstract class DurationFormatterUtils { @@ -90,7 +89,6 @@ public abstract class DurationFormatterUtils { * @return the printed result */ public static String print(Duration value, DurationFormat.Style style, @Nullable DurationFormat.Unit unit) { - Assert.notNull(value, "Value must not be null"); return switch (style) { case ISO8601 -> value.toString(); case SIMPLE -> printSimple(value, unit); diff --git a/spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java b/spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java index 3174834e0cc..6a4a17931e6 100644 --- a/spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java +++ b/spring-context/src/test/java/org/springframework/format/datetime/standard/DurationFormatterUtilsTests.java @@ -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))