### Question:
PortSelectUtils { public synchronized static int selectAvailablePort(int defaultPort, int maxLength) { for (int i = defaultPort; i < defaultPort + maxLength; i++) { try { if (available(i)) { return i; } } catch (IllegalArgumentException e) { } } return -1; }  synchronized static int selectAvailablePort(int defaultPort, int maxLength); static final int MIN_PORT_NUMBER; static final int MAX_PORT_NUMBER; }### Answer:
@Test public void selectSinglePort() { try (ServerSocket ss = new ServerSocket(1234)) { int port = PortSelectUtils.selectAvailablePort(1234, 1); AssertUtils.isTrue(port == -1, "Select Error Port."); } catch (IOException ex) { } }
@Test public void selectMaximumPort() { int port = PortSelectUtils.selectAvailablePort(65555, 10); AssertUtils.isTrue(port == -1, "Select Error Port."); }
@Test public void selectMinimumPort() { int port = PortSelectUtils.selectAvailablePort(1050, 100); AssertUtils.isTrue(port == PortSelectUtils.MIN_PORT_NUMBER, "Select Error Port."); }
@Test public void selectUnusedPort() { int port = PortSelectUtils.selectAvailablePort(1234, 100); AssertUtils.isTrue(port == 1234, "Select Error Port."); }
@Test public void selectUsedPort() { try (ServerSocket ss = new ServerSocket(1234)) { int port = PortSelectUtils.selectAvailablePort(1234, 100); AssertUtils.isTrue(port == 1235, "Select Error Port."); } catch (IOException ex) { } }