|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
34 | 34 | import static java.nio.charset.StandardCharsets.UTF_8;
|
35 | 35 | import static org.assertj.core.api.Assertions.assertThat;
|
36 | 36 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
37 |
| -import static org.assertj.core.api.Assertions.catchThrowable; |
38 | 37 | import static org.mockito.BDDMockito.given;
|
39 | 38 | import static org.mockito.Mockito.mock;
|
40 | 39 |
|
@@ -197,16 +196,16 @@ void handleErrorForCustomClientError() throws Exception {
|
197 | 196 | given(response.getHeaders()).willReturn(headers);
|
198 | 197 | given(response.getBody()).willReturn(body);
|
199 | 198 |
|
200 |
| - Throwable throwable = catchThrowable(() -> handler.handleError(URI.create("/"), HttpMethod.GET, response)); |
201 |
| - |
202 |
| - // validate exception |
203 |
| - assertThat(throwable).isInstanceOf(HttpClientErrorException.class); |
204 |
| - HttpClientErrorException actualHttpClientErrorException = (HttpClientErrorException) throwable; |
205 |
| - assertThat(actualHttpClientErrorException.getStatusCode()).isEqualTo(statusCode); |
206 |
| - assertThat(actualHttpClientErrorException.getStatusText()).isEqualTo(statusText); |
207 |
| - assertThat(actualHttpClientErrorException.getResponseHeaders()).isEqualTo(headers); |
208 |
| - assertThat(actualHttpClientErrorException.getMessage()).contains(responseBody); |
209 |
| - assertThat(actualHttpClientErrorException.getResponseBodyAsString()).isEqualTo(responseBody); |
| 199 | + assertThatExceptionOfType(HttpClientErrorException.class) |
| 200 | + .isThrownBy(() -> handler.handleError(URI.create("/"), HttpMethod.GET, response)) |
| 201 | + .satisfies(ex -> { |
| 202 | + // validate exception |
| 203 | + assertThat(ex.getStatusCode()).isEqualTo(statusCode); |
| 204 | + assertThat(ex.getStatusText()).isEqualTo(statusText); |
| 205 | + assertThat(ex.getResponseHeaders()).isEqualTo(headers); |
| 206 | + assertThat(ex.getMessage()).contains(responseBody); |
| 207 | + assertThat(ex.getResponseBodyAsString()).isEqualTo(responseBody); |
| 208 | + }); |
210 | 209 | }
|
211 | 210 |
|
212 | 211 | @Test // SPR-17461
|
@@ -237,16 +236,16 @@ void handleErrorForCustomServerError() throws Exception {
|
237 | 236 | given(response.getHeaders()).willReturn(headers);
|
238 | 237 | given(response.getBody()).willReturn(body);
|
239 | 238 |
|
240 |
| - Throwable throwable = catchThrowable(() -> handler.handleError(URI.create("/"), HttpMethod.GET, response)); |
241 |
| - |
242 |
| - // validate exception |
243 |
| - assertThat(throwable).isInstanceOf(HttpServerErrorException.class); |
244 |
| - HttpServerErrorException actualHttpServerErrorException = (HttpServerErrorException) throwable; |
245 |
| - assertThat(actualHttpServerErrorException.getStatusCode()).isEqualTo(statusCode); |
246 |
| - assertThat(actualHttpServerErrorException.getStatusText()).isEqualTo(statusText); |
247 |
| - assertThat(actualHttpServerErrorException.getResponseHeaders()).isEqualTo(headers); |
248 |
| - assertThat(actualHttpServerErrorException.getMessage()).contains(responseBody); |
249 |
| - assertThat(actualHttpServerErrorException.getResponseBodyAsString()).isEqualTo(responseBody); |
| 239 | + assertThatExceptionOfType(HttpServerErrorException.class) |
| 240 | + .isThrownBy(() -> handler.handleError(URI.create("/"), HttpMethod.GET, response)) |
| 241 | + .satisfies(ex -> { |
| 242 | + // validate exception |
| 243 | + assertThat(ex.getStatusCode()).isEqualTo(statusCode); |
| 244 | + assertThat(ex.getStatusText()).isEqualTo(statusText); |
| 245 | + assertThat(ex.getResponseHeaders()).isEqualTo(headers); |
| 246 | + assertThat(ex.getMessage()).contains(responseBody); |
| 247 | + assertThat(ex.getResponseBodyAsString()).isEqualTo(responseBody); |
| 248 | + }); |
250 | 249 | }
|
251 | 250 |
|
252 | 251 | @Test // SPR-16604
|
|
0 commit comments