### Question:
HttpServletRequestUtils { public static String extractClientIp(HttpServletRequest request) { Preconditions.checkNotNull(request); String ipAddress = request.getHeader("X-FORWARDED-FOR"); if (ipAddress == null) { ipAddress = request.getRemoteAddr(); } return ipAddress; } private  HttpServletRequestUtils(); static String extractClientIp(HttpServletRequest request); static String extractScheme(HttpServletRequest request); static String extractHost(HttpServletRequest request); static int extractServerPort(HttpServletRequest request); static String constructRequestBaseUrl(HttpServletRequest request); static String constructRequestUrl(HttpServletRequest request); static String constructRequestUrlWithParameters(HttpServletRequest request); static boolean isDefaultPort(String scheme, int port);  }### Answer:
@Test(expected=NullPointerException.class) public void extractClientIp_NULL() { HttpServletRequestUtils.extractClientIp(null); }
@Test public void extractClientIp_X_FORWARDED_FOR() { when(request.getHeader("X-FORWARDED-FOR")).thenReturn("12.12.12.12"); assertEquals("12.12.12.12", HttpServletRequestUtils.extractClientIp(request)); }
@Test public void extractClientIp_NO_X_FORWARDED_FOR() { when(request.getHeader("X-FORWARDED-FOR")).thenReturn(null); when(request.getRemoteAddr()).thenReturn("13.13.13.13"); assertEquals("13.13.13.13", HttpServletRequestUtils.extractClientIp(request)); }