@Test public void testPortValidator() { int port = 45893; Assert.assertTrue(PortValidator.checkPort(port)); }
public static boolean checkPort(int port) { try (ServerSocket serverSocket = new ServerSocket()) { serverSocket.bind(new InetSocketAddress(port)); return true; } catch (Exception exception) { return false; } }
PortValidator { public static boolean checkPort(int port) { try (ServerSocket serverSocket = new ServerSocket()) { serverSocket.bind(new InetSocketAddress(port)); return true; } catch (Exception exception) { return false; } } }
PortValidator { public static boolean checkPort(int port) { try (ServerSocket serverSocket = new ServerSocket()) { serverSocket.bind(new InetSocketAddress(port)); return true; } catch (Exception exception) { return false; } }  }
PortValidator { public static boolean checkPort(int port) { try (ServerSocket serverSocket = new ServerSocket()) { serverSocket.bind(new InetSocketAddress(port)); return true; } catch (Exception exception) { return false; } }  static boolean checkPort(int port); static boolean checkHost(String host, int port); static int findFreePort(int startPort); }
PortValidator { public static boolean checkPort(int port) { try (ServerSocket serverSocket = new ServerSocket()) { serverSocket.bind(new InetSocketAddress(port)); return true; } catch (Exception exception) { return false; } }  static boolean checkPort(int port); static boolean checkHost(String host, int port); static int findFreePort(int startPort);  }