### Question:
ServletUtil { public static HttpRequest fromHttpServletRequest(HttpServletRequest servletReq) throws IOException { HttpRequest req = new HttpRequest(new UriBuilder(servletReq).toUri()); Enumeration<?> headerNames = servletReq.getHeaderNames(); while (headerNames.hasMoreElements()) { Object obj = headerNames.nextElement(); if (obj instanceof String) { String headerName = (String) obj; Enumeration<?> headerValues = servletReq.getHeaders(headerName); while (headerValues.hasMoreElements()) { obj = headerValues.nextElement(); if (obj instanceof String) { req.addHeader(headerName, (String) obj); } } } } req.setMethod(servletReq.getMethod()); if ("POST".equalsIgnoreCase(req.getMethod())) { req.setPostBody(servletReq.getInputStream()); } req.setParam(REMOTE_ADDR_KEY, servletReq.getRemoteAddr()); return req; } private  ServletUtil(); static HttpRequest fromHttpServletRequest(HttpServletRequest servletReq); static void setCachingHeaders(HttpResponseBuilder response, int ttl, boolean noProxy); static void copyToServletResponseAndOverrideCacheHeaders(
      HttpResponse response, HttpServletResponse servletResponse); static void copyToServletResponse(
      HttpResponse response, HttpServletResponse servletResponse); static void copyContentToServletResponse(
      HttpResponse response, HttpServletResponse servletResponse); static void copyHeadersAndStatusToServletResponse(
      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 testFromHttpServletRequest() throws Exception { HttpServletRequest original = EasyMock.createMock(HttpServletRequest.class); EasyMock.expect(original.getScheme()).andReturn("https"); EasyMock.expect(original.getServerName()).andReturn("www.example.org"); EasyMock.expect(original.getServerPort()).andReturn(444); EasyMock.expect(original.getRequestURI()).andReturn("/path/foo"); EasyMock.expect(original.getQueryString()).andReturn("one=two&three=four"); Vector<String> headerNames = new Vector<String>(); headerNames.add("Header1"); headerNames.add("Header2"); EasyMock.expect(original.getHeaderNames()).andReturn(headerNames.elements()); EasyMock.expect(original.getHeaders("Header1")) .andReturn(makeEnumeration("HVal1", "HVal3")); EasyMock.expect(original.getHeaders("Header2")) .andReturn(makeEnumeration("HVal2", "HVal4")); EasyMock.expect(original.getMethod()).andReturn("post"); final ByteArrayInputStream bais = new ByteArrayInputStream("post body".getBytes()); ServletInputStream sis = new ServletInputStream() { @Override public int read() throws IOException { return bais.read(); } }; EasyMock.expect(original.getInputStream()).andReturn(sis); EasyMock.expect(original.getRemoteAddr()).andReturn("1.2.3.4"); EasyMock.replay(original); HttpRequest request = ServletUtil.fromHttpServletRequest(original); EasyMock.verify(original); assertEquals(Uri.parse("https: request.getUri()); assertEquals(3, request.getHeaders().size()); assertEquals("HVal1", request.getHeaders("Header1").get(0)); assertEquals("HVal3", request.getHeaders("Header1").get(1)); assertEquals("HVal2", request.getHeaders("Header2").get(0)); assertEquals("HVal4", request.getHeaders("Header2").get(1)); assertEquals("post", request.getMethod()); assertEquals("post body", request.getPostBodyAsString()); assertEquals("1.2.3.4", request.getParam(ServletUtil.REMOTE_ADDR_KEY)); }