public static NetworkEndpoint forHostnameAndPort(String hostname, int port) {
    checkArgument(
        0 <= port && port <= MAX_PORT_NUMBER,
        "Port out of range. Expected [0, %s], actual %s.",
        MAX_PORT_NUMBER,
        port);

    return forHostname(hostname).toBuilder()
        .setType(NetworkEndpoint.Type.HOSTNAME_PORT)
        .setPort(Port.newBuilder().setPortNumber(port))
        .build();
  }
@Test
  public void forHostnameAndPort_withInvalidPort_throwsIllegalArgumentException() {
    assertThrows(
        IllegalArgumentException.class, () -> NetworkEndpointUtils.forHostnameAndPort("abc", -1));
    assertThrows(
        IllegalArgumentException.class,
        () -> NetworkEndpointUtils.forHostnameAndPort("abc", 65536));
  }