From 3cf68819d6e86fe92bbdd47836e4227c5b3921e1 Mon Sep 17 00:00:00 2001 From: Scott Leberknight <174812+sleberknight@users.noreply.github.com> Date: Sat, 1 Apr 2023 13:33:55 -0400 Subject: [PATCH] JaxrsExceptionTestHelper#assertContainsError should report actual errors (#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 --- .../test/jaxrs/exception/JaxrsExceptionTestHelper.java | 8 ++++---- .../jaxrs/exception/JaxrsExceptionTestHelperTest.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/kiwiproject/test/jaxrs/exception/JaxrsExceptionTestHelper.java b/src/main/java/org/kiwiproject/test/jaxrs/exception/JaxrsExceptionTestHelper.java index 46095364..afa1299b 100644 --- a/src/main/java/org/kiwiproject/test/jaxrs/exception/JaxrsExceptionTestHelper.java +++ b/src/main/java/org/kiwiproject/test/jaxrs/exception/JaxrsExceptionTestHelper.java @@ -119,14 +119,14 @@ public static void assertHasErrors(Response response, List 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); }); } diff --git a/src/test/java/org/kiwiproject/test/jaxrs/exception/JaxrsExceptionTestHelperTest.java b/src/test/java/org/kiwiproject/test/jaxrs/exception/JaxrsExceptionTestHelperTest.java index f05e10be..02a5d7d3 100644 --- a/src/test/java/org/kiwiproject/test/jaxrs/exception/JaxrsExceptionTestHelperTest.java +++ b/src/test/java/org/kiwiproject/test/jaxrs/exception/JaxrsExceptionTestHelperTest.java @@ -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()); } } }