ConnectionHelperBean implements ConnectionHelper { @Override public ConnectionInformation getConnectionInformation(URI uri) throws AmbiguousResultException, IllegalArgumentException { if (uri == null) { throw new IllegalArgumentException("Cannot download content - given URI is null"); } else if (!uri.isAbsolute()) { throw new IllegalArgumentException("Cannot download content - given URI is not a URL"); } String protocol = uri.getScheme(); String host = getHost(uri); Integer port = getPort(uri); String username = getUsername(uri); RemoteRepositoryAuthentication result = getRemoteRepositoryAuthentication(protocol, host, port, username); return constructConnectionInformation(result); }  @Override ConnectionInformation getConnectionInformation(URI uri); @Override Integer getPort(URI uri); @Override String getHost(URI uri); @Override String getUsername(URI uri); @Override String getPassword(URI uri);  }
@Test public void shouldGetConnectionInformationProperly() throws Exception { ConnectionInformation tested = connectionHelper.getConnectionInformation(new URI("http: ConnectionInformation expected = new ConnectionInformation("example.com", 80, "test", "passwd"); Assert.assertEquals(expected, tested); }
@Test(expected = AmbiguousResultException.class) public void shouldGetAmbiguousResultException() throws Exception { connectionHelper.getConnectionInformation(new URI("ftp: }