@Test
public void testFromParts() {

  HostAndPort hp = HostAndPort.fromParts("gmail.com", 81);
  assertEquals("gmail.com", hp.getHost());
  assertTrue(hp.hasPort());
  assertEquals(81, hp.getPort());
  try {
    HostAndPort.fromParts("gmail.com:80", 81);
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
  }
  try {
    HostAndPort.fromParts("gmail.com", -1);
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
  }
}