### Question:
IOUtils { public static int chooseFreePort() throws IOException { try (ServerSocket socket = new ServerSocket(0, 0)) { return socket.getLocalPort(); } } private  IOUtils(); static void deleteRecursively(Path rootDir); static List<Path> listFiles(Path dir, String glob); static void closeQuietly(Closeable closeable); static int chooseFreePort();  }### Answer:
@Test public void testChooseFreePort() throws IOException { int freePort = IOUtils.chooseFreePort(); assertRange(freePort, 1024, 65535); try (ServerSocket socket = new ServerSocket(freePort, 0)) { assertEquals(freePort, socket.getLocalPort()); } }
@Test public void testDistinctFreePorts() throws IOException { Set<Integer> ports = new HashSet<>(); for (int i = 0; i < 10; i++) { ports.add(IOUtils.chooseFreePort()); } assertEquals(10, ports.size()); }