|
23 | 23 |
|
24 | 24 | import org.junit.jupiter.api.Nested;
|
25 | 25 | import org.junit.jupiter.api.Test;
|
| 26 | +import org.junit.jupiter.params.ParameterizedTest; |
| 27 | +import org.junit.jupiter.params.provider.EnumSource; |
26 | 28 |
|
| 29 | +import org.springframework.format.annotation.DurationFormat; |
27 | 30 | import org.springframework.format.annotation.DurationFormat.Unit;
|
28 | 31 |
|
29 | 32 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -188,6 +191,22 @@ void parseCompositeBadUnit() {
|
188 | 191 | .havingCause().withMessage("Does not match composite duration pattern");
|
189 | 192 | }
|
190 | 193 |
|
| 194 | + @ParameterizedTest |
| 195 | + @EnumSource(DurationFormat.Style.class) |
| 196 | + void parseEmptyStringThrowsForAllStyles(DurationFormat.Style style) { |
| 197 | + assertThatIllegalArgumentException() |
| 198 | + .isThrownBy(() -> DurationFormatterUtils.parse("", style)) |
| 199 | + .withMessage("Value must not be empty"); |
| 200 | + } |
| 201 | + |
| 202 | + @ParameterizedTest |
| 203 | + @EnumSource(DurationFormat.Style.class) |
| 204 | + void parseNullStringThrowsForAllStyles(DurationFormat.Style style) { |
| 205 | + assertThatIllegalArgumentException() |
| 206 | + .isThrownBy(() -> DurationFormatterUtils.parse(null, style)) |
| 207 | + .withMessage("Value must not be empty"); |
| 208 | + } |
| 209 | + |
191 | 210 | @Test
|
192 | 211 | void printSimple() {
|
193 | 212 | assertThat(DurationFormatterUtils.print(Duration.ofNanos(12345), SIMPLE, Unit.NANOS))
|
@@ -240,6 +259,14 @@ void printCompositeNegative() {
|
240 | 259 | .isEqualTo("-1d2h34m57s28ms3us2ns");
|
241 | 260 | }
|
242 | 261 |
|
| 262 | + @ParameterizedTest |
| 263 | + @EnumSource(DurationFormat.Style.class) |
| 264 | + void printNullDurationThrowsForAllStyles(DurationFormat.Style style) { |
| 265 | + assertThatIllegalArgumentException() |
| 266 | + .isThrownBy(() -> DurationFormatterUtils.print(null, style)) |
| 267 | + .withMessage("Value must not be null"); |
| 268 | + } |
| 269 | + |
243 | 270 | @Test
|
244 | 271 | void detectAndParse() {
|
245 | 272 | assertThat(DurationFormatterUtils.detectAndParse("PT1.234S", Unit.NANOS))
|
|
0 commit comments