@Test public void assertTestIsAbleToGetNextIntOfRange() { EmulatorPortFinder finder = new DefaultPortFinder(MIN_PORT, MAX_PORT); for (int i = MIN_PORT; i <= MAX_PORT; i += 2) { Assert.assertEquals(i, finder.next().intValue()); } Assert.assertNull(finder.next()); }
@Override public synchronized Integer next() { if (availablePorts.isEmpty()) { return null; } Collections.sort(availablePorts); Integer port = availablePorts.get(0); portsInUse.add(port); availablePorts.remove(port); return port; }
DefaultPortFinder implements EmulatorPortFinder { @Override public synchronized Integer next() { if (availablePorts.isEmpty()) { return null; } Collections.sort(availablePorts); Integer port = availablePorts.get(0); portsInUse.add(port); availablePorts.remove(port); return port; } }
DefaultPortFinder implements EmulatorPortFinder { @Override public synchronized Integer next() { if (availablePorts.isEmpty()) { return null; } Collections.sort(availablePorts); Integer port = availablePorts.get(0); portsInUse.add(port); availablePorts.remove(port); return port; } DefaultPortFinder(Integer minPort, Integer maxPort); }
DefaultPortFinder implements EmulatorPortFinder { @Override public synchronized Integer next() { if (availablePorts.isEmpty()) { return null; } Collections.sort(availablePorts); Integer port = availablePorts.get(0); portsInUse.add(port); availablePorts.remove(port); return port; } DefaultPortFinder(Integer minPort, Integer maxPort); @Override synchronized Integer next(); @Override synchronized void release(Integer port); }
DefaultPortFinder implements EmulatorPortFinder { @Override public synchronized Integer next() { if (availablePorts.isEmpty()) { return null; } Collections.sort(availablePorts); Integer port = availablePorts.get(0); portsInUse.add(port); availablePorts.remove(port); return port; } DefaultPortFinder(Integer minPort, Integer maxPort); @Override synchronized Integer next(); @Override synchronized void release(Integer port);  }