AvailablePortProvider { public static AvailablePortProvider between(int from, int to) { return new AvailablePortProvider(from, to, NetUtils::isAvailable); } AvailablePortProvider(int from, int to, Function<Integer, Boolean> portChecker); static AvailablePortProvider between(int from, int to); int nextPort();  }
@Test public void testInvalidRanges() throws Exception { try { AvailablePortProvider.between(0, 1); fail("Should not reach this line"); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }