StubResponseWriter { public void writeResponse(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { byte[] responseBody = stubResponseGenerator.generateResponse(req, resp); if (responseBody != null) { responseBody = stubResponseProcessor.processResponse(req, resp, responseBody); writeResponseToOutputStream(resp, responseBody); } else { writeErrorResponse(resp); logger.warn("Wilma has got an unwanted request from this address: " + req.getRemoteAddr()); } }  void writeResponse(final HttpServletRequest req, final HttpServletResponse resp);  }
@Test public void testWriteResponseShouldGenerateResponse() throws IOException { underTest.writeResponse(req, resp); verify(stubResponseGenerator).generateResponse(req, resp); }
@Test public void testWriteResponseShouldProcessResponse() throws IOException { given(stubResponseGenerator.generateResponse(req, resp)).willReturn(byteArray); underTest.writeResponse(req, resp); verify(stubResponseProcessor).processResponse(req, resp, byteArray); }
@Test public void testWriteResponseShouldWriteResponseToServletOutputStream() throws IOException { given(stubResponseGenerator.generateResponse(req, resp)).willReturn(byteArray); given(stubResponseProcessor.processResponse(req, resp, byteArray)).willReturn(byteArray); underTest.writeResponse(req, resp); verify(resp).getOutputStream(); verify(outputStream).write(byteArray); verify(outputStream).close(); }
@Test public void testWriteResponseShouldAnswerWithErrorWhenGetUnwantedRequest() throws IOException { given(stubResponseGenerator.generateResponse(req, resp)).willReturn(null); underTest.writeResponse(req, resp); verify(resp).getOutputStream(); verify(resp).setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); verify(outputStream).write(ERROR_MESSAGE_FOR_UNWANTED_REQUESTS.getBytes()); verify(outputStream).close(); }