URLConverter implements PropertyConverter<URL> { @Override public URL convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(),"<URL>"); if(value==null){ return null; } String trimmed = value.trim(); try { return new URL(trimmed); } catch (Exception e) { LOG.log(Level.FINE, "Unparseable URL: " + trimmed, e); } return null; }  @Override URL convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testConvert_URL() throws Exception { URLConverter converter = new URLConverter(); assertThat(new URL("http: }
@Test public void testConvert_URL_WithSpaces() throws Exception { URLConverter converter = new URLConverter(); assertThat(new URL("http: }
@Test public void testConvert_URL_WithSpacesBefore() throws Exception { URLConverter converter = new URLConverter(); assertThat(new URL("http: }
@Test public void testConvert_URL_WithSpacesAfter() throws Exception { URLConverter converter = new URLConverter(); assertThat(new URL("http: }
@Test public void testConvert_NotPresent() throws Exception { URLConverter converter = new URLConverter(); assertThat(converter.convert("", context)).isNull(); assertThat(converter.convert(null, context)).isNull(); }
@Test public void testConvert_URLInvalid() throws ConfigException { URLConverter converter = new URLConverter(); assertThat(converter.convert("not a url", context)).isNull(); }
@Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(URL.class)).build(); URLConverter converter = new URLConverter(); converter.convert("http: assertThat(context.getSupportedFormats()).contains("<URL> (URLConverter)"); }