Skip to content

Commit

Permalink
JaxrsExceptionTestHelper#assertContainsError should report actual err…
Browse files Browse the repository at this point in the history
…ors (#380)

* Change the error message reported by assertContainsError so that it
  reports the expected ErrorMessage and also all the actual errors. This
  will allow users to determine the problem by having the actual errors
  for inspection.

Closes #376
  • Loading branch information
sleberknight authored Apr 1, 2023
1 parent bee2fc8 commit 3cf6881
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public static void assertHasErrors(Response response, List<ErrorMessage> errorMe
public static ErrorMessage assertContainsError(Response response, int statusCode, String substring) {
var jaxrsException = toJaxrsException(response);

return jaxrsException.getErrors()
.stream()
var errors = jaxrsException.getErrors();
return errors.stream()
.filter(error -> matchesArguments(error, statusCode, substring))
.findFirst()
.orElseThrow(() -> {
var assertErrorMessage =
f("Response does not contain an ErrorMessage having status {} and message containing: {}",
statusCode, substring);
f("Response does not contain an ErrorMessage having status {} and message containing: '{}'. Actual errors: {}",
statusCode, substring, errors);
return new AssertionError(assertErrorMessage);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ void shouldThrow_WhenResponseDoesNotContainTheError(int statusCode, String subst
assertThatThrownBy(() ->
JaxrsExceptionTestHelper.assertContainsError(response, statusCode, substring))
.isInstanceOf(AssertionError.class)
.hasMessage("Response does not contain an ErrorMessage having status %d and message containing: %s",
statusCode, substring);
.hasMessage("Response does not contain an ErrorMessage having status %d and message containing: '%s'. Actual errors: %s",
statusCode, substring, jaxrsException.getErrors());
}
}
}

0 comments on commit 3cf6881

Please sign in to comment.