CompressionServletResponseWrapper extends FilterServletResponseWrapper { CompressionServletResponseWrapper(HttpServletResponse response, int compressionThreshold) { super(response); assert compressionThreshold >= 0; this.compressionThreshold = compressionThreshold; } CompressionServletResponseWrapper(HttpServletResponse response, int compressionThreshold); @Override ServletOutputStream createOutputStream(); @Override void setContentLength(int length);  }
@Test public void testCompressionServletResponseWrapper() throws IOException { final CompressionServletResponseWrapper wrapper = new CompressionServletResponseWrapper( new HttpResponse(), 1024); wrapper.setStatus(HttpServletResponse.SC_NOT_FOUND); assertEquals("status", HttpServletResponse.SC_NOT_FOUND, wrapper.getCurrentStatus()); wrapper.sendError(HttpServletResponse.SC_BAD_GATEWAY); assertEquals("status", HttpServletResponse.SC_BAD_GATEWAY, wrapper.getCurrentStatus()); wrapper.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "message"); assertEquals("status", HttpServletResponse.SC_SERVICE_UNAVAILABLE, wrapper.getCurrentStatus()); assertNotNull("outputStream", wrapper.createOutputStream()); assertNotNull("writer", wrapper.getWriter()); wrapper.flushStream(); wrapper.flushBuffer(); wrapper.close(); wrapper.setContentLength(0); wrapper.finishResponse(); boolean ok = false; try { wrapper.getOutputStream(); } catch (final Exception e) { ok = true; } assertTrue("exception", ok); final CompressionServletResponseWrapper wrapper2 = new CompressionServletResponseWrapper( new HttpResponse(), 1024); assertNotNull("outputStream", wrapper2.getOutputStream()); wrapper2.flushBuffer(); wrapper2.close(); boolean ok2 = false; try { wrapper2.getWriter(); } catch (final Exception e) { ok2 = true; } assertTrue("exception", ok2); }