@Test
public void testRequireBracketsForIPv6() {

  // Bracketed IPv6 works fine.
  assertEquals("::1", HostAndPort.fromString("[::1]").requireBracketsForIPv6().getHost());
  assertEquals("::1", HostAndPort.fromString("[::1]:80").requireBracketsForIPv6().getHost());
  // Non-bracketed non-IPv6 works fine.
  assertEquals("x", HostAndPort.fromString("x").requireBracketsForIPv6().getHost());
  assertEquals("x", HostAndPort.fromString("x:80").requireBracketsForIPv6().getHost());
  // Non-bracketed IPv6 fails.
  try {
    HostAndPort.fromString("::1").requireBracketsForIPv6();
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
  }
}