### Question:
NetworkUtil { public static String getClientIp(HttpServletRequest request) { String clientIp = OpenStorefrontConstant.NOT_AVAILABLE; if (request != null) { clientIp = request.getRemoteAddr(); String clientIpFromHeader = request.getHeader("x-forwarded-for"); if (StringUtils.isNotBlank(clientIpFromHeader)) { clientIp = clientIp + " Forward for: " + clientIpFromHeader; } else { clientIpFromHeader = request.getHeader("x-real-ip"); if (StringUtils.isNotBlank(clientIpFromHeader)) { clientIp = clientIp + " X-real IP: " + clientIpFromHeader; } } } return clientIp; } private  NetworkUtil(); static String getClientIp(HttpServletRequest request);  }### Answer:
@Test public void testGetClientIp() { LOG.info("getClientIp"); HttpServletRequest request = Mockito.mock(MockHttpServletRequest.class); LOG.info("Scenario 1: null request"); String result = NetworkUtil.getClientIp(null); assertEquals(OpenStorefrontConstant.NOT_AVAILABLE, result); LOG.info("Scenario 2: Empty header"); Mockito.when(request.getRemoteAddr()).thenReturn("unittest"); Mockito.when(request.getHeader(Mockito.anyString())).thenReturn(null); String expResult = "unittest"; result = NetworkUtil.getClientIp(request); assertEquals(expResult, result); LOG.info("Scenario 3: Forward header"); Mockito.when(request.getHeader("x-forwarded-for")).thenReturn("1"); expResult = "unittest Forward for: 1"; result = NetworkUtil.getClientIp(request); assertEquals(expResult, result); LOG.info("Scenario 4: Real IP header"); request = Mockito.mock(MockHttpServletRequest.class); Mockito.when(request.getRemoteAddr()).thenReturn("unittest"); Mockito.when(request.getHeader("x-real-ip")).thenReturn("2"); expResult = "unittest X-real IP: 2"; result = NetworkUtil.getClientIp(request); assertEquals(expResult, result); }