AddressUtils { public static InetSocketAddress createUnresolved(String hostname, int port) { return createInetSocketAddress(hostname, port, false); } 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 shouldCreateUnresolvedAddressByHostName() { InetSocketAddress socketAddress = AddressUtils.createUnresolved("example.com", 80); assertThat(socketAddress.isUnresolved()).isTrue(); assertThat(socketAddress.getPort()).isEqualTo(80); assertThat(socketAddress.getHostString()).isEqualTo("example.com"); }
@Test public void shouldAlwaysCreateResolvedNumberIPAddress() { InetSocketAddress socketAddress = AddressUtils.createUnresolved("127.0.0.1", 8080); assertThat(socketAddress.isUnresolved()).isFalse(); assertThat(socketAddress.getAddress().getHostAddress()).isEqualTo("127.0.0.1"); assertThat(socketAddress.getPort()).isEqualTo(8080); assertThat(socketAddress.getHostString()).isEqualTo("127.0.0.1"); }
@Test public void createUnresolvedBadValues() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> AddressUtils.createUnresolved(null, 0)) .withMessage("hostname"); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> AddressUtils.createUnresolved("hostname", -1)) .withMessage("port out of range:-1"); }