AddressUtils { public static InetSocketAddress replaceWithResolved(InetSocketAddress inetSocketAddress) { requireNonNull(inetSocketAddress, "inetSocketAddress"); if (!inetSocketAddress.isUnresolved()) { return inetSocketAddress; } inetSocketAddress = replaceUnresolvedNumericIp(inetSocketAddress); if (!inetSocketAddress.isUnresolved()) { return inetSocketAddress; } else { return new InetSocketAddress(inetSocketAddress.getHostString(), inetSocketAddress.getPort()); } } 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 shouldNotReplaceIfAlreadyResolved() { InetSocketAddress socketAddress = new InetSocketAddress("example.com", 80); InetSocketAddress processedAddress = AddressUtils.replaceWithResolved(socketAddress); assertThat(processedAddress).isSameAs(socketAddress); }
@Test public void replaceWithResolvedBadValues() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> AddressUtils.replaceWithResolved(null)) .withMessage("inetSocketAddress"); }