use of com.tvd12.ezyhttp.server.core.handler.UnhandledErrorHandler in project ezyhttp by youngmonkeys.
the class UnhandledErrorHandlerTest method defaultNull.
@Test
public void defaultNull() {
// given
UnhandledErrorHandler sut = new UnhandledErrorHandler() {
};
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
// when
Object actual = sut.handleError(HttpMethod.GET, request, response, StatusCodes.BAD_REQUEST, null);
// then
Asserts.assertNull(actual);
}
use of com.tvd12.ezyhttp.server.core.handler.UnhandledErrorHandler in project ezyhttp by youngmonkeys.
the class UnhandledErrorHandlerTest method returnResponseEntity.
@Test
public void returnResponseEntity() {
// given
ResponseEntity result = ResponseEntity.ok();
UnhandledErrorHandler sut = new UnhandledErrorHandler() {
@Override
public Object processError(HttpMethod method, HttpServletRequest request, HttpServletResponse response, int errorStatusCode, Exception exception) {
return result;
}
};
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
// when
Object actual = sut.handleError(HttpMethod.GET, request, response, StatusCodes.BAD_REQUEST, null);
// then
Asserts.assertEquals(result, actual);
verify(response, times(1)).setContentType(null);
verify(response, times(1)).setContentType(ContentTypes.APPLICATION_JSON);
}
use of com.tvd12.ezyhttp.server.core.handler.UnhandledErrorHandler in project ezyhttp by youngmonkeys.
the class UnhandledErrorHandlerTest method returnView.
@Test
public void returnView() {
// given
View result = View.builder().template("foo").build();
UnhandledErrorHandler sut = new UnhandledErrorHandler() {
@Override
public Object processError(HttpMethod method, HttpServletRequest request, HttpServletResponse response, int errorStatusCode, Exception exception) {
return result;
}
};
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getContentType()).thenReturn(ContentTypes.TEXT_HTML_UTF8);
// when
Object actual = sut.handleError(HttpMethod.GET, request, response, StatusCodes.BAD_REQUEST, null);
// then
Asserts.assertEquals(result, actual);
verify(response, times(1)).setContentType(ContentTypes.TEXT_HTML_UTF8);
}
Aggregations