int port = DEFAULT_PORT; try { String[] hostAndPort = ConfigUtils.getHostAndPort(host); host = hostAndPort[0]; if (hostAndPort.length == 2) {
@Test(expected = ConfigException.class) public void testGetHostAndPortWithoutBracket() throws ConfigException { String[] nsa = ConfigUtils.getHostAndPort("[2001:db8:85a3:8d3:1319:8a2e:370:7348"); }
@Test(expected = ConfigException.class) public void testGetHostAndPortWithoutPortAfterColon() throws ConfigException { String[] nsa = ConfigUtils.getHostAndPort("[2001:db8:1::242:ac11:2]:"); }
String serverParts[] = ConfigUtils.getHostAndPort(serverClientParts[0]); if ((serverClientParts.length > 2) || (serverParts.length < 3) || (serverParts.length > 4)) { String clientParts[] = ConfigUtils.getHostAndPort(serverClientParts[1]); if (clientParts.length > 2) { throw new ConfigException(addressStr + wrongFormat);
String[] host_port; try { host_port = ConfigUtils.getHostAndPort(addr); } catch (ConfigException e) { throw new InitialMessageException("Badly formed address: %s", addr);
@Test public void testGetHostAndPortWithoutPort() throws ConfigException { String[] nsa = ConfigUtils.getHostAndPort("127.0.0.1"); assertEquals(nsa[0], "127.0.0.1"); assertEquals(nsa.length, 1); nsa = ConfigUtils.getHostAndPort("[2001:db8:1::242:ac11:2]"); assertEquals(nsa[0], "2001:db8:1::242:ac11:2"); assertEquals(nsa.length, 1); }
@Test public void testGetHostAndPortWithIPv4() throws ConfigException { String[] nsa = ConfigUtils.getHostAndPort("127.0.0.1:443"); assertEquals(nsa[0], "127.0.0.1"); assertEquals(nsa[1], "443"); nsa = ConfigUtils.getHostAndPort("127.0.0.1:2888:3888"); assertEquals(nsa[0], "127.0.0.1"); assertEquals(nsa[1], "2888"); assertEquals(nsa[2], "3888"); }
@Test public void testGetHostAndPortWithIPv6() throws ConfigException { String[] nsa = ConfigUtils.getHostAndPort("[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443"); assertEquals(nsa[0], "2001:db8:85a3:8d3:1319:8a2e:370:7348"); assertEquals(nsa[1], "443"); nsa = ConfigUtils.getHostAndPort("[2001:db8:1::242:ac11:2]:2888:3888"); assertEquals(nsa[0], "2001:db8:1::242:ac11:2"); assertEquals(nsa[1], "2888"); assertEquals(nsa[2], "3888"); }