@Test
public void testFromHost() {

  HostAndPort hp = HostAndPort.fromHost("gmail.com");
  assertEquals("gmail.com", hp.getHost());
  assertFalse(hp.hasPort());
  hp = HostAndPort.fromHost("[::1]");
  assertEquals("::1", hp.getHost());
  assertFalse(hp.hasPort());
  try {
    HostAndPort.fromHost("gmail.com:80");
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
  }
  try {
    HostAndPort.fromHost("[gmail.com]");
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
  }
}