|
|
|
|
@ -41,6 +41,22 @@ import static org.springframework.format.annotation.DurationFormat.Style.SIMPLE;
@@ -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 {
@@ -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 {
@@ -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)) |
|
|
|
|
|