DefaultResponseErrorHandler.hasError tolerates unknown status codes

Issue: SPR-16108
This commit is contained in:
Juergen Hoeller
2017-10-24 15:44:37 +02:00
parent be5b9354a9
commit ab19c227d3
2 changed files with 26 additions and 7 deletions

View File

@@ -33,6 +33,7 @@ import static org.mockito.BDDMockito.*;
* Unit tests for {@link DefaultResponseErrorHandler}.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
*/
public class DefaultResponseErrorHandlerTests {
@@ -67,8 +68,8 @@ public class DefaultResponseErrorHandlerTests {
handler.handleError(response);
fail("expected HttpClientErrorException");
}
catch (HttpClientErrorException e) {
assertSame(headers, e.getResponseHeaders());
catch (HttpClientErrorException ex) {
assertSame(headers, ex.getResponseHeaders());
}
}
@@ -103,11 +104,22 @@ public class DefaultResponseErrorHandlerTests {
headers.setContentType(MediaType.TEXT_PLAIN);
given(response.getStatusCode()).willThrow(new IllegalArgumentException("No matching constant for 999"));
given(response.getRawStatusCode()).willReturn(999);
given(response.getStatusText()).willReturn("Custom status code");
given(response.getHeaders()).willReturn(headers);
handler.handleError(response);
}
@Test // SPR-16108
public void hasErrorForUnknownStatusCode() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
given(response.getStatusCode()).willThrow(new IllegalArgumentException("No matching constant for 999"));
given(response.getStatusText()).willReturn("Custom status code");
given(response.getHeaders()).willReturn(headers);
assertFalse(handler.hasError(response));
}
}