ServerHandler { public static boolean hostAvailabilityCheck(String host, int port, int times) throws InterruptedException { int i = 0; while (i < times) { LOGGER.trace("Checking host availability for the host: " + host + " and the port: " + port); try (Socket s = new Socket(host, port)) { LOGGER.info(host + ":" + port + " is available"); return true; } catch (IOException e) { Thread.sleep(5000); i++; } } return false; }  static boolean hostAvailabilityCheck(String host, int port, int times);  }
@Test public void testHostAvailabilityCheck() { String host = "localhost"; int port = 8002; int times = 2; try { assertEquals(false, ServerHandler.hostAvailabilityCheck(host, port, times)); } catch (InterruptedException e) { assertTrue(false); } }