### Question:
HttpServletRequestUtils { public static int extractServerPort(HttpServletRequest request) { Preconditions.checkNotNull(request); int port = request.getIntHeader("X-FORWARDED-PORT"); if (port == -1) { port = request.getServerPort(); } return port; } 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 extractServetPort_NULL() { HttpServletRequestUtils.extractServerPort(null); }
@Test public void extractServerPort_X_FORWARDED_PORT() { when(request.getIntHeader("X-FORWARDED-PORT")).thenReturn(123); assertEquals(123, HttpServletRequestUtils.extractServerPort(request)); }
@Test public void extractServerPort_NO_X_FORWARDED_PORT() { when(request.getIntHeader("X-FORWARDED-PORT")).thenReturn(-1); when(request.getServerPort()).thenReturn(123); assertEquals(123, HttpServletRequestUtils.extractServerPort(request)); }