Proxy { public static Proxy create(final URI uri) { Proxy proxy = new Proxy(uri.getHost(), uri.getPort(), uri.getScheme()); String userInfo = uri.getUserInfo(); if (userInfo != null) { String[] up = userInfo.split(":"); if (up.length == 1) { proxy.username = up[0].isEmpty() ? null : up[0]; } else { proxy.username = up[0].isEmpty() ? null : up[0]; proxy.password = up[1].isEmpty() ? null : up[1]; } } return proxy; } Proxy(String host, int port);  Proxy(String host, int port, String scheme);  Proxy(String host, int port, String username, String password); static Proxy create(final URI uri); String getScheme(); void setScheme(String scheme); String getHost(); int getPort(); String getUsername(); String getPassword(); URI toURI(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void testCreate() { Proxy proxy = Proxy.create(URI.create(" assertNull(proxy.getScheme()); assertNull(proxy.getUsername()); assertNull(proxy.getPassword()); assertEquals("127.0.0.1", proxy.getHost()); assertEquals(8080, proxy.getPort()); proxy = Proxy.create(URI.create("http: assertEquals("http", proxy.getScheme()); assertNull(proxy.getUsername()); assertNull(proxy.getPassword()); assertEquals("127.0.0.1", proxy.getHost()); assertEquals(8080, proxy.getPort()); proxy = Proxy.create(URI.create(" assertNull(proxy.getScheme()); assertEquals("username", proxy.getUsername()); assertEquals("password", proxy.getPassword()); assertEquals("127.0.0.1", proxy.getHost()); assertEquals(8080, proxy.getPort()); proxy = Proxy.create(URI.create(" assertNull(proxy.getScheme()); assertEquals("username", proxy.getUsername()); assertNull(proxy.getPassword()); assertEquals("127.0.0.1", proxy.getHost()); assertEquals(8080, proxy.getPort()); proxy = Proxy.create(URI.create(" assertNull(proxy.getScheme()); assertNull(proxy.getUsername()); assertEquals("password", proxy.getPassword()); assertEquals("127.0.0.1", proxy.getHost()); assertEquals(8080, proxy.getPort()); }