### Question:
NetUtils { public static String[] getIPV6HostAndPort(String hostPort) { if (hostPort.startsWith("[")) { int i = hostPort.lastIndexOf(']'); if (i < 0) { throw new IllegalArgumentException( hostPort + " starts with '[' but has no matching ']'"); } String host = hostPort.substring(1, i); if (host.isEmpty()) { throw new IllegalArgumentException(host + " is empty."); } if (hostPort.length() > i + 1) { return getHostPort(hostPort, i, host); } return new String[] { host }; } else { return new String[] {}; } }  static String formatInetAddr(InetSocketAddress addr); static String[] getIPV6HostAndPort(String hostPort);  }### Answer:
@Test public void tetGetIPV6HostAndPort_WhenHostDoesNotEndWithBracket() { assertThrows(IllegalArgumentException.class, () -> { NetUtils.getIPV6HostAndPort("[2001:0db8:85a3:0000:0000:8a2e:0370:7334:443"); }); }
@Test public void tetGetIPV6HostAndPort_WhenNoPortAfterColon() { assertThrows(IllegalArgumentException.class, () -> { NetUtils.getIPV6HostAndPort("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:"); }); }
@Test public void tetGetIPV6HostAndPort_WhenPortIsNotSeparatedProperly() { assertThrows(IllegalArgumentException.class, () -> { NetUtils.getIPV6HostAndPort("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]2181"); }); }
@Test public void tetGetIPV6HostAndPort_WhenHostIsEmpty() { assertThrows(IllegalArgumentException.class, () -> { 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]); }