From 01fef00a8288673eb994a1b9cb32f3aac01abaab Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Tue, 23 Jul 2024 12:29:17 +0200 Subject: [PATCH] feat(impl): [#639] fix broken tests after merge --- .../eclipse/tractusx/irs/policystore/common/DateUtils.java | 5 ++++- .../tractusx/irs/policystore/common/DateUtilsTest.java | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/common/DateUtils.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/common/DateUtils.java index b127d9495..4f9f13b6b 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/common/DateUtils.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/common/DateUtils.java @@ -50,6 +50,9 @@ public static boolean isDateBefore(final OffsetDateTime dateTime, final String r } public static boolean isDateAfter(final OffsetDateTime dateTime, final String referenceDateString) { + if (StringUtils.isBlank(referenceDateString)) { + throw new IllegalArgumentException("Invalid date: must not be blank!"); + } if (isDateWithoutTime(referenceDateString)) { return dateTime.isAfter(toOffsetDateTimeAtEndOfDay(referenceDateString)); } else { @@ -99,7 +102,7 @@ public static boolean isDateWithoutTime(final String referenceDateString) { return false; } catch (DateTimeParseException e) { log.trace(e.getMessage(), e); - throw new IllegalArgumentException("Invalid date format: " + referenceDateString); + throw new IllegalArgumentException("Invalid date format: " + referenceDateString, e); } } } diff --git a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/common/DateUtilsTest.java b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/common/DateUtilsTest.java index 41aedcee3..2a68d3de4 100644 --- a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/common/DateUtilsTest.java +++ b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/common/DateUtilsTest.java @@ -117,8 +117,7 @@ public void testIsDateWithoutTimeWithInvalidDate() { } @ParameterizedTest - @ValueSource(strings = { "3333-11-11T11:11:11.111Z", - "3333-11-", + @ValueSource(strings = { "3333-11-", "2222", "asdf" }) @@ -126,7 +125,6 @@ void testInvalidDate(final String referenceDateStr) { final ThrowingCallable call = () -> DateUtils.isDateAfter(OffsetDateTime.now(), referenceDateStr); assertThatThrownBy(call).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Invalid date") - .hasMessageContaining("refer to the documentation") .hasCauseInstanceOf(DateTimeParseException.class); }