UrlValueConverter extends AbstractValueConverter<URL> { @Override public URL convert(String s) throws IllegalArgumentException { try { return new URL(StringUtils.removeTrailingSlash(s)); } catch (MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } } private  UrlValueConverter(); @Override URL convert(String s); @Override String toString(URL value); @Override String toSafeString(URL value); static final ValueConverter<URL> INSTANCE; }
@Test public void testConvert() throws Exception { SoftAssertions.assertSoftly(softly -> { softly.assertThat(converter.toString(converter.convert("http: softly.assertThat(converter.toString(converter.convert("http: softly.assertThat(converter.toString(converter.convert("http: softly.assertThat(converter.convert("http: }); }
@Test public void testConvertNull() throws Exception { assertThatThrownBy(() -> converter.convert(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void testConvertInvalid() throws Exception { assertThatThrownBy(() -> converter.convert("invalid")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void testConvertNoProtocol() throws Exception { assertThatThrownBy(() -> converter.convert("www.example.com")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("no protocol"); }