HostAndPort implements Serializable { public HostAndPort requireBracketsForIPv6() { if (hasBracketlessColons) { throw new IllegalArgumentException( String.format("Possible bracketless IPv6 literal: %s", host)); } return this; } private  HostAndPort(String host, int port, boolean hasBracketlessColons); String getHost(); boolean hasPort(); int getPort(); int getPortOrDefault(int defaultPort); static HostAndPort fromParts(String host, int port); static HostAndPort fromHost(String host); static HostAndPort fromString(String hostPortString); HostAndPort withDefaultPort(int defaultPort); HostAndPort requireBracketsForIPv6(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString();  }
@Test public void testRequireBracketsForIPv6() { assertEquals("::1", HostAndPort.fromString("[::1]").requireBracketsForIPv6().getHost()); assertEquals("::1", HostAndPort.fromString("[::1]:80").requireBracketsForIPv6().getHost()); assertEquals("x", HostAndPort.fromString("x").requireBracketsForIPv6().getHost()); assertEquals("x", HostAndPort.fromString("x:80").requireBracketsForIPv6().getHost()); try { HostAndPort.fromString("::1").requireBracketsForIPv6(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }