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