UrlUtil { public static URL toURL(final String string) { try { LOGGER.trace("Converting '{}' to URL.", string); return new URL(string); } catch (final MalformedURLException ex) { final File f = new File(string); try { LOGGER.trace("Converting '{}' to URL as a file.", string); return f.getAbsoluteFile() .toURI() .toURL(); } catch (final MalformedURLException ex2) { throw new IllegalArgumentException("Incorrect location configuration.", ex2); } } } private  UrlUtil(); static URL toURL(final String string); static URLConnection open(final URL url);  }
@Test void toUrlValid() { final URL url = UrlUtil.toURL("http: assertThat(url).hasProtocol("http"); }
@Test void toUrlInvalid() { final URL url = UrlUtil.toURL("noproto: assertThat(url).hasProtocol("file"); }