HttpUtils { public static boolean isReachable(final String hostName, int port, int timeout) { try (Socket socket = new Socket()) { socket.connect(new InetSocketAddress(hostName, port), timeout); return true; } catch (IOException ignore) { return false; } } private  HttpUtils(); static boolean isReachable(final String hostName, int port, int timeout); static URL buildURL(final String hostName, final Map<String, String> query);  }
@Test public void existingAddressIsReachable() throws Exception { val host = "www.google.com"; val port = 443; val timeout = 10000; assertTrue(isReachable(host, port, timeout)); }
@Test public void notExistingAddressIsUnreacheble() throws Exception { val host = "sadasdsadsd"; val port = 80; val timeout = 10000; assertFalse(isReachable(host, port, timeout)); }