URIConverter implements IStringConverter<URI> { @Override public URI convert(String uriString) { checkNotNull(uriString, "uriString is null"); try { if (uriString.isEmpty()) { return new URI(uriString); } URL url = new URL(uriString); return new URI( url.getProtocol(), url.getUserInfo(), IDN.toASCII(url.getHost()), url.getPort(), url.getPath(), url.getQuery(), url.getRef()).normalize(); } catch (MalformedURLException e) { throw new ParameterException("Malformed URL: " + e.getMessage()); } catch (URISyntaxException e) { throw new ParameterException("Malformed URI: " + e.getMessage()); } }  @Override URI convert(String uriString);  }
@Test(expected = NullPointerException.class) public void givenValueIsNull_whenConvert_thenThrowsNullPointerException() { converter.convert(null); }
@Test public void givenBlankURI_whenConvert_thenReturnsExpectedURI() { URI result = converter.convert(""); assertThat(result, equalTo(URI.create(""))); }
@Test(expected = ParameterException.class) public void givenInvalidURI_whenConvert_thenThrowsParameterException() { converter.convert(":"); }
@Test public void givenValidURI_whenConvert_thenReturnsExpectedURI() { URI result = converter.convert("http: assertThat(result, equalTo(URI.create("http: }
@Test public void givenValidIDN_whenConvert_thenReturnsExpectedURI() { URI result = converter.convert("http: assertThat(result, equalTo(URI.create("http: }
@Test public void givenValidIDN2_whenConvert_thenReturnsExpectedURI() { URI result = converter.convert("http: assertThat(result, equalTo(URI.create("http: }
@Test public void givenValidIDN3_whenConvert_thenReturnsExpectedURI() { URI result = converter.convert("http: assertThat(result.toString(), equalTo("http: }