Skip to content

Commit

Permalink
Cleanup: replace usages of deprecated catchThrowableOfType (#1156)
Browse files Browse the repository at this point in the history
* Use the catchThrowableOfType that has the Class argument first
  • Loading branch information
sleberknight authored Jun 18, 2024
1 parent 4b9e222 commit 4d300dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/test/java/org/kiwiproject/jaxrs/KiwiResourcesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1023,8 +1023,8 @@ void shouldDoNothing_WhenListContainsOneElement() {
@NullAndEmptySource
void shouldThrowBadRequest_WhenListIsNullOrEmpty(List<Object> values) {
var thrown = catchThrowableOfType(
() -> KiwiResources.assertOneElementOrThrowBadRequest(values, "testParam"),
JaxrsBadRequestException.class);
JaxrsBadRequestException.class,
() -> KiwiResources.assertOneElementOrThrowBadRequest(values, "testParam"));

assertThat(thrown.getMessage()).isEqualTo("testParam has no values, but exactly one was expected");
assertThat(thrown.getErrors()).hasSize(1);
Expand All @@ -1035,8 +1035,8 @@ void shouldThrowBadRequest_WhenListHasMoreThanOneElement() {
var values = List.of("42", "84");

var thrown = catchThrowableOfType(
() -> KiwiResources.assertOneElementOrThrowBadRequest(values, "testParam"),
JaxrsBadRequestException.class);
JaxrsBadRequestException.class,
() -> KiwiResources.assertOneElementOrThrowBadRequest(values, "testParam"));

assertThat(thrown.getMessage()).isEqualTo("testParam has 2 values, but only one was expected");
assertThat(thrown.getErrors()).hasSize(1);
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/org/kiwiproject/retry/KiwiRetryerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ void whenUsingDefaultExceptions_AndThrowsOtherException() {

var retryer = KiwiRetryer.<Response>newRetryerWithDefaultExceptions("thisFails");

var kiwiRetryerException = catchThrowableOfType(() -> retryer.call(callable), KiwiRetryerException.class);
var kiwiRetryerException = catchThrowableOfType(KiwiRetryerException.class,
() -> retryer.call(callable));

assertThat(kiwiRetryerException)
.hasMessage("KiwiRetryer thisFails failed all 1 attempts. Error: Retrying failed to complete successfully after 1 attempts.");
Expand Down Expand Up @@ -374,7 +375,8 @@ void whenRetryRuntimeExceptions_ShouldSupersedeNamedPredicates() {
.exceptionPredicate(KiwiRetryerPredicates.UNKNOWN_HOST)
.build();

var kiwiRetryerException = catchThrowableOfType(() -> retryer.call(callable), KiwiRetryerException.class);
var kiwiRetryerException = catchThrowableOfType(KiwiRetryerException.class,
() -> retryer.call(callable));

assertThat(kiwiRetryerException)
.hasMessage("KiwiRetryer retryOnAllRuntimeExceptionsShouldTakePrecedence failed all 1 attempts." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ void shouldValidate_InvalidObjects() {
var contactDetails = new SampleContactDetails("bob@example.org", "");
var bob = new SamplePerson("Bob", null, null, contactDetails);

var exception = catchThrowableOfType(() -> KiwiValidations.validateThrowing(bob), ConstraintViolationException.class);
var exception = catchThrowableOfType(ConstraintViolationException.class,
() -> KiwiValidations.validateThrowing(bob));
var violations = exception.getConstraintViolations();
assertThat(violations)
.extracting(v -> v.getPropertyPath().toString())
Expand All @@ -186,7 +187,8 @@ void shouldValidate_InvalidObjects() {
var contactDetails = new SampleContactDetails("bob@example.org", "");
var bob = new SamplePerson(null, "S", null, contactDetails);

var exception = catchThrowableOfType(() -> KiwiValidations.validateThrowing(bob, Default.class, Secret.class), ConstraintViolationException.class);
var exception = catchThrowableOfType(ConstraintViolationException.class,
() -> KiwiValidations.validateThrowing(bob, Default.class, Secret.class));
var violations = exception.getConstraintViolations();
assertThat(violations)
.extracting(v -> v.getPropertyPath().toString())
Expand Down

0 comments on commit 4d300dd

Please sign in to comment.