### Question:
AddressBuilder { public static Address create(String url) throws IllegalArgumentException { try { URI u = new URI(url); String scheme = u.getScheme(); String host = u.getHost(); if (scheme != null && host == null) return AddressBuilder.begin().scheme(u.getScheme()).schemeSpecificPart(u.getRawSchemeSpecificPart()) .buildLiteral(); else return AddressBuilder.begin().scheme(scheme).domain(host).port(u.getPort()) .path(u.getRawPath()).queryLiteral(u.getRawQuery()).anchor(u.getRawFragment()).buildLiteral(); } catch (URISyntaxException e) { throw new IllegalArgumentException( "[" + url + "] is not a valid URL fragment. Consider encoding relevant portions of the URL with [" + Encoder.class + "], or use the provided builder pattern via this class to specify part encoding.", e); } } protected  AddressBuilder(); static AddressBuilderBase begin(); static Address create(String url); @Override String toString();  }### Answer:
@Test public void testFromStringWithFullUrl() { Address address = AddressBuilder.create("http: assertEquals("http", address.getScheme()); assertEquals("www.google.com", address.getDomain()); assertEquals(Integer.valueOf(80), address.getPort()); assertEquals("/search", address.getPath()); assertEquals("q=foobar", address.getQuery()); assertEquals("/search?q=foobar", address.getPathAndQuery()); }
@Test public void testFromStringWithoutPort() { Address address = AddressBuilder.create("http: assertEquals("http", address.getScheme()); assertEquals("www.google.com", address.getDomain()); assertEquals(null, address.getPort()); assertEquals("/search", address.getPath()); assertEquals("q=foobar", address.getQuery()); assertEquals("/search?q=foobar", address.getPathAndQuery()); }
@Test public void testFromStringOnlyWithPathAndQuery() { Address address = AddressBuilder.create("/search?q=foobar"); assertEquals(null, address.getScheme()); assertEquals(null, address.getDomain()); assertEquals(null, address.getPort()); assertEquals("/search", address.getPath()); assertEquals("q=foobar", address.getQuery()); assertEquals("/search?q=foobar", address.getPathAndQuery()); }
@Test public void testFromStringOnlyWithPathAndQuery2() { Address address = AddressBuilder.create("search?q=foobar"); assertEquals(null, address.getScheme()); assertEquals(null, address.getDomain()); assertEquals(null, address.getPort()); assertEquals("search", address.getPath()); assertEquals("q=foobar", address.getQuery()); assertEquals("search?q=foobar", address.getPathAndQuery()); }