URIBuilder { public static URI toURI(String urlStr) { try { final URL url = new URL(urlStr); final Integer port = Optional.of(url.getPort()).filter(p -> !p.equals(-1)).orElse(url.getDefaultPort()); final URI uri = url.toURI(); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), port, uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (MalformedURLException | URISyntaxException e) { throw new IllegalArgumentException("Not valid URI: " + urlStr, e); } } private  URIBuilder(); static URI toURI(String urlStr);  }
@Test void testToURIHttpNoPort() { URI jobServiceURL = URIBuilder.toURI("http: assertHttp(jobServiceURL, "http", 80); }
@Test void testToURIHttpsNoPort() { URI jobServiceURL = URIBuilder.toURI("https: assertHttp(jobServiceURL, "https", 443); }
@Test void testToURIHttpWithPort() { URI jobServiceURL = URIBuilder.toURI("http: assertHttp(jobServiceURL, "http", 8080); }
@Test void testToURIHttpsWithPort() { URI jobServiceURL = URIBuilder.toURI("https: assertHttp(jobServiceURL, "https", 4443); }