DefaultHttpResult implements HttpResult { public void sendError(int statusCode) { try { response.sendError(statusCode); } catch (IOException e) { throw new ResultException("Error while setting status code", e); } } DefaultHttpResult(HttpServletResponse response, Status status); HttpResult addDateHeader(String name, long date); HttpResult addHeader(String name, String value); HttpResult addIntHeader(String name, int value); void sendError(int statusCode); void sendError(int statusCode, String message); void setStatusCode(int statusCode); void movedPermanentlyTo(String uri); T movedPermanentlyTo(final Class<T> controller); HttpResult body(String body); HttpResult body(InputStream body); HttpResult body(Reader body);  }
@Test public void shouldSendError() throws Exception { httpResult.sendError(SC_INTERNAL_SERVER_ERROR); verify(response).sendError(SC_INTERNAL_SERVER_ERROR); }
@Test public void shouldThrowsResultExceptionIfAnIOExceptionWhenSendError() throws Exception { doThrow(new IOException()).when(response).sendError(anyInt()); try { httpResult.sendError(SC_INTERNAL_SERVER_ERROR); fail("should throw ResultException"); } catch (ResultException e) { verify(response, only()).sendError(anyInt()); } }
@Test public void shouldSendErrorWithMessage() throws Exception { httpResult.sendError(SC_INTERNAL_SERVER_ERROR, "A simple message"); verify(response).sendError(SC_INTERNAL_SERVER_ERROR, "A simple message"); }
@Test public void shouldThrowResultExceptionIfAnIOExceptionWhenSendErrorWithMessage() throws Exception { doThrow(new IOException()).when(response).sendError(anyInt(), anyString()); try { httpResult.sendError(SC_INTERNAL_SERVER_ERROR, "A simple message"); fail("should throw ResultException"); } catch (ResultException e) { verify(response, only()).sendError(anyInt(), anyString()); } }