### Question:
UrlBuilder { public URL toURL() throws MalformedURLException { return new URL(toString()); } UrlBuilder();  UrlBuilder(String url);  UrlBuilder(URL url); void addPath(String path); void addQuery(String query); String getHost(); String getPath(); int getPort(); String getProtocol(); String getQuery(); Map<String, String> getQueryParameters(); String getRef(); void setHost(String host); void setPath(String path); void setPort(int port); void setProtocol(String protocol); void setQuery(String query); void setQueryParameters(Map<String, String> queryParameters); void setRef(String ref); void setUrl(URL url); @Override String toString(); URL toURL();  }### Answer:
@Test public void testToURL() { URL input = createUrl("http: UrlBuilder builder = new UrlBuilder(input); Assert.assertEquals("http", builder.getProtocol()); Assert.assertEquals("www.blah.com", builder.getHost()); Assert.assertEquals(8080, builder.getPort()); Assert.assertEquals("/something/getKml.pl", builder.getPath()); Assert.assertEquals("a=b&c=d", builder.getQuery()); Assert.assertEquals("ref", builder.getRef()); Assert.assertEquals("b", builder.getQueryParameters().get("a")); try { Assert.assertEquals(input.toString(), builder.toURL().toString()); } catch (MalformedURLException e) { Assert.fail(e.getMessage()); } }