|
@@ -69,4 +69,49 @@ public class NetUtilsTest extends ZKTestCase {
|
|
|
assertEquals("doesnt.exist.com:1234", NetUtils.formatInetAddr(isa));
|
|
|
}
|
|
|
|
|
|
+ @Test(expected = IllegalArgumentException.class)
|
|
|
+ public void tetGetIPV6HostAndPort_WhenHostDoesNotEndWithBracket() {
|
|
|
+ NetUtils.getIPV6HostAndPort("[2001:0db8:85a3:0000:0000:8a2e:0370:7334:443");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = IllegalArgumentException.class)
|
|
|
+ public void tetGetIPV6HostAndPort_WhenNoPortAfterColon() {
|
|
|
+ NetUtils.getIPV6HostAndPort("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = IllegalArgumentException.class)
|
|
|
+ public void tetGetIPV6HostAndPort_WhenPortIsNotSeparatedProperly() {
|
|
|
+ NetUtils.getIPV6HostAndPort("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]2181");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = IllegalArgumentException.class)
|
|
|
+ public void tetGetIPV6HostAndPort_WhenHostIsEmpty() {
|
|
|
+ NetUtils.getIPV6HostAndPort("[]:2181");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void tetGetIPV6HostAndPort_EmptyStringArrayIfDoesNotStartWithBracket() {
|
|
|
+ String[] ipv6HostAndPort =
|
|
|
+ NetUtils.getIPV6HostAndPort("2001:0db8:85a3:0000:0000:8a2e:0370:7334]");
|
|
|
+ assertEquals(0, ipv6HostAndPort.length);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void tetGetIPV6HostAndPort_ReturnHostPort() {
|
|
|
+ String[] ipv6HostAndPort =
|
|
|
+ NetUtils.getIPV6HostAndPort("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2181");
|
|
|
+ assertEquals(2, ipv6HostAndPort.length);
|
|
|
+ assertEquals("2001:0db8:85a3:0000:0000:8a2e:0370:7334", ipv6HostAndPort[0]);
|
|
|
+ assertEquals("2181", ipv6HostAndPort[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void tetGetIPV6HostAndPort_ReturnHostPortPort() {
|
|
|
+ String[] ipv6HostAndPort =
|
|
|
+ NetUtils.getIPV6HostAndPort("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2181:3181");
|
|
|
+ assertEquals(2, ipv6HostAndPort.length);
|
|
|
+ assertEquals("2001:0db8:85a3:0000:0000:8a2e:0370:7334", ipv6HostAndPort[0]);
|
|
|
+ assertEquals("2181:3181", ipv6HostAndPort[1]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|