### Question:
ServletUtil { public static void copyResponseToServlet(HttpResponse response, HttpServletResponse servletResponse) throws IOException { servletResponse.setStatus(response.getHttpStatusCode()); servletResponse.setContentLength(response.getContentLength()); for (Map.Entry<String, String> header : response.getHeaders().entries()) { servletResponse.addHeader(header.getKey(), header.getValue()); } HttpUtil.setCachingHeaders(servletResponse, (int)(response.getCacheTtl() / 1000L)); IOUtils.copy(response.getResponse(), servletResponse.getOutputStream()); } private  ServletUtil(); static HttpRequest fromHttpServletRequest(HttpServletRequest servletReq); static void setCachingHeaders(HttpResponseBuilder response, int ttl, boolean noProxy); static void copyResponseToServlet(HttpResponse response, HttpServletResponse servletResponse); static Uri validateUrl(Uri urlToValidate); static void setXForwardedForHeader(HttpRequest inboundRequest, HttpRequest req); static void setXForwardedForHeader(HttpServletRequest inboundRequest, HttpRequest req); static HttpResponse errorResponse(GadgetException e); static HttpResponse convertToJsonResponse(HttpResponse response); static final String REMOTE_ADDR_KEY; static final String DATA_URI_KEY; }### Answer:
@Test public void testCopyResponseToServlet() throws Exception { FakeTimeSource fakeTime = new FakeTimeSource(); HttpUtil.setTimeSource(fakeTime); HttpResponse response = new HttpResponseBuilder() .setResponseString("response string").setHttpStatusCode(200).addHeader("h1", "v1") .addHeader("h2", "v2").setCacheTtl(1000).create(); HttpServletResponse servletResponse = EasyMock.createMock(HttpServletResponse.class); HttpServletResponseRecorder recorder = new HttpServletResponseRecorder(servletResponse); ServletUtil.copyResponseToServlet(response, recorder); assertEquals(200, recorder.getHttpStatusCode()); assertEquals("response string", recorder.getResponseAsString()); assertEquals("v1", recorder.getHeader("h1")); assertEquals("v2", recorder.getHeader("h2")); assertEquals("public,max-age=1000", recorder.getHeader("Cache-Control")); }
@Test public void testCopyResponseToServletNoCache() throws Exception { HttpResponse response = new HttpResponseBuilder() .setResponseString("response string").setHttpStatusCode(200).addHeader("h1", "v1") .addHeader("h2", "v2").setStrictNoCache().create(); HttpServletResponse servletResponse = EasyMock.createMock(HttpServletResponse.class); HttpServletResponseRecorder recorder = new HttpServletResponseRecorder(servletResponse); FakeTimeSource fakeTime = new FakeTimeSource(); HttpUtil.setTimeSource(fakeTime); ServletUtil.copyResponseToServlet(response, recorder); assertEquals(200, recorder.getHttpStatusCode()); assertEquals("response string", recorder.getResponseAsString()); assertEquals("v1", recorder.getHeader("h1")); assertEquals("v2", recorder.getHeader("h2")); assertEquals("no-cache", recorder.getHeader("Pragma")); assertEquals("no-cache", recorder.getHeader("Cache-Control")); }