UrlUtil { public static Object tryCreateURL(String serialized) { Object object; try { object = new URL(serialized); } catch (final MalformedURLException ex) { throw new IllegalArgumentException(String.format( "Specified URL '%s' is malformed.", serialized ), ex); } return object; } private  UrlUtil(); static Object tryCreateURL(String serialized);  }
@Test void tryCreateURL() { final Object object = UrlUtil.tryCreateURL(URL_STRING); if (object instanceof URL) { final URL url = (URL) object; assertEquals(URL_STRING, url.toString()); } else { fail(object.getClass().getName() + " does not extend " + URL.class.getName()); } }
@Test void tryCreateURLIllegal() { assertThrows(IllegalArgumentException.class, () -> UrlUtil.tryCreateURL("a")); }