AddressUtils { public static InetSocketAddress createInetSocketAddress(String hostname, int port, boolean resolve) { requireNonNull(hostname, "hostname"); InetSocketAddress inetAddressForIpString = createForIpString(hostname, port); if (inetAddressForIpString != null) { return inetAddressForIpString; } else { return resolve ? new InetSocketAddress(hostname, port) : InetSocketAddress.createUnresolved(hostname, port); } } private  AddressUtils(); static InetSocketAddress createInetSocketAddress(String hostname, int port, boolean resolve); static InetSocketAddress createResolved(String hostname, int port); static InetSocketAddress createUnresolved(String hostname, int port); static InetSocketAddress parseAddress(String address, int defaultPort); static InetSocketAddress replaceUnresolvedNumericIp(InetSocketAddress inetSocketAddress); static InetSocketAddress replaceWithResolved(InetSocketAddress inetSocketAddress); static SocketAddress updateHost(@Nullable Supplier<? extends SocketAddress> address, String host); static SocketAddress updatePort(@Nullable Supplier<? extends SocketAddress> address, int port);  }
@Test public void createInetSocketAddressBadValues() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> AddressUtils.createInetSocketAddress(null, 0, true)) .withMessage("hostname"); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> AddressUtils.createInetSocketAddress("hostname", -1, true)) .withMessage("port out of range:-1"); }