AddressUtils { public static SocketAddress updateHost(@Nullable Supplier<? extends SocketAddress> address, String host) { if (address == null) { return createUnresolved(host, 0); } SocketAddress socketAddress = address.get(); if (socketAddress instanceof DomainSocketAddress) { throw new IllegalArgumentException("Cannot update DomainSocketAddress with host name [" + host + "]."); } if (!(socketAddress instanceof InetSocketAddress)) { return createUnresolved(host, 0); } InetSocketAddress inet = (InetSocketAddress) socketAddress; return createUnresolved(host, inet.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 updateHostBadValues() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> AddressUtils.updateHost(null, null)) .withMessage("hostname"); }