Skip to content

Commit

Permalink
chore(exception-handling): [#639] Resolve PMD warning by preserving t…
Browse files Browse the repository at this point in the history
…he cause in exception handling
  • Loading branch information
dsmf committed Jul 19, 2024
1 parent 7ef4abb commit 93bee26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static LocalDate parseDate(final String dateString) {
try {
return LocalDate.parse(dateString);
} catch (DateTimeParseException e) {
throw new IllegalArgumentException("Invalid date format (please refer to the documentation)");
throw new IllegalArgumentException("Invalid date format (please refer to the documentation)", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.util.stream.Stream;

import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
Expand Down Expand Up @@ -78,7 +79,8 @@ 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");
.hasMessageContaining("refer to the documentation")
.hasCauseInstanceOf(DateTimeParseException.class);
}

@ParameterizedTest
Expand All @@ -91,7 +93,8 @@ void testInvalidDateBlank(final String referenceDateStr) {
final ThrowingCallable call = () -> DateUtils.isDateAfter(OffsetDateTime.now(), referenceDateStr);
assertThatThrownBy(call).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Invalid date")
.hasMessageContaining("must not be blank");
.hasMessageContaining("must not be blank")
.hasNoCause();
}

}

0 comments on commit 93bee26

Please sign in to comment.