### Question:
UriParser { public int getPort(String serverUri) { try { return new URI(serverUri).getPort(); } catch (URISyntaxException e) { throw new ConfigurationException(e); } }  String getHost(String s); int getPort(String serverUri);  }### Answer:
@Test public void parserReturnsPortGivenHttpUrl() { String url = "tcp: UriParser uriParser = new UriParser(); int parsedPort = uriParser.getPort(url); Assert.assertEquals(8080, parsedPort); }
@Test public void parserReturnsPortGivenIpUrl() { String url = "tcp: UriParser uriParser = new UriParser(); int parsedPort = uriParser.getPort(url); Assert.assertEquals(8080, parsedPort); }
@Test public void getPortThrowsOnInvalidUri() { String url = "%s"; UriParser uriParser = new UriParser(); expectedException.expect(ConfigurationException.class); uriParser.getPort(url); }