IoUtil { public static int getFreeRandomPort() { return getFreeRandomPort(49152, 65535, 100); }  static void download(Logger log, URL downloadUrl, File target); static int getFreeRandomPort(); static int getFreeRandomPort(int min, int max, int attempts); static String sanitizeFileName(String name);  }
@Test public void findOpenPort() throws IOException { int port = IoUtil.getFreeRandomPort(); try (ServerSocket ss = new ServerSocket(port)) { } }
@Test public void findOpenPortWhenPortsAreBusy() throws IOException { int port = IoUtil.getFreeRandomPort(49152, 60000, 100); try (ServerSocket ss = new ServerSocket(port)) { } int port2 = IoUtil.getFreeRandomPort(port, 65535, 100); try (ServerSocket ss = new ServerSocket(port2)) { } assertTrue(port2 > port); }