XUrl { public static InetSocketAddress inetSocket(String url) throws URISyntaxException { Preconditions.checkNotNull(url); Matcher matcher = URL_PROTOCOL_REGEX.matcher(url); url = addProtocol(url); URI uri = new URI(url); if (uri.getPort() == -1) { if (!matcher.find()) { return new InetSocketAddress(uri.getHost(), 80); } else { return new InetSocketAddress(uri.getHost(), 443); } } else { return new InetSocketAddress(uri.getHost(), uri.getPort()); } }  static String host(String url); static int port(String url); static String domainChecked(String url); static String path(String url); static String stripUrlParameters(String url); static String stripUrlParameters(URL url); static String rawQueryParameters(String url); static String addProtocol(String url); static Map<String, List<String>> decodeQueryString(String url); static InetSocketAddress inetSocket(String url);  }
@Test void getInetSocket() throws java.net.URISyntaxException { InetSocketAddress result = XUrl.inetSocket(url2); assertEquals("api.nordstrom.com", result.getHostString()); assertEquals(8080, result.getPort()); }
@Test void getInetSocket_withNoPort() throws java.net.URISyntaxException { InetSocketAddress result = XUrl.inetSocket(url1); assertEquals("api.nordstrom.com", result.getHostString()); assertEquals(443, result.getPort()); }
@Test void getInetSocket_withNoProtocol() throws java.net.URISyntaxException { InetSocketAddress result = XUrl.inetSocket("api.nordstrom.com/foo/v1?foo=bar"); assertEquals("api.nordstrom.com", result.getHostString()); assertEquals(80, result.getPort()); }