HttpResponseWrapper extends HttpServletResponseWrapper implements ResponseWithSessionId { @Override public PrintWriter getWriter() throws IOException { if (outputStream != null) { throw new IllegalStateException("Only one of getWriter()/getOutputStream() can be called, and output stream is already used."); } if (writer == null) { writer = wrapPrintWriter(); } return writer; } HttpResponseWrapper(HttpRequestWrapper request, HttpServletResponse response); @Override final void sendError(int sc); @Override final void sendError(int sc, String msg); @Override final void sendRedirect(String location); @Override SaveSessionServletOutputStream getOutputStream(); @Override PrintWriter getWriter(); @Override void addHeader(String name, String value); @Override void setHeader(String name, String value); @Override void setContentLength(int len); @Override void reset(); @Override String encodeURL(String url); @Override void flushBuffer();  }
@Test public void testPropagateWriterFlush() throws IOException { PrintWriter w = responseWrapper.getWriter(); verify(response, never()).getWriter(); verify(requestWrapper, never()).propagateSession(); w.flush(); verify(requestWrapper).propagateSession(); }
@Test public void testTwiceWriter() throws IOException { PrintWriter writer1 = responseWrapper.getWriter(); PrintWriter writer2 = responseWrapper.getWriter(); assertSame(writer1, writer2); }