### Question:
ETagFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { ETaggingHttpResponse taggingResponse = createTaggingResponse(request, response); try { chain.doFilter(request, taggingResponse); } finally { taggingResponse.writeToOutput(); } } else { chain.doFilter(request, response); } }  void init(FilterConfig filterConfig); void destroy(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain);  }### Answer:
@Test public void testTagContent() throws Exception { chain.write(RESPONSE_BODY_BYTES); control.replay(); filter.doFilter(request, response, chain); assertArrayEquals(RESPONSE_BODY_BYTES, stream.getBuffer()); control.verify(); }
@Test public void testTagContentOnException() throws Exception { chain.write(RESPONSE_BODY_BYTES); chain.throwException(); control.replay(); try { filter.doFilter(request, response, chain); fail("Should have thrown an IOException"); } catch (IOException e) { } assertArrayEquals(RESPONSE_BODY_BYTES, stream.getBuffer()); control.verify(); }