CidrBlockAuthorisation { public boolean isAuthorised(List<String> cidrBlocks, String address) { return any(cache.getUnchecked(cidrBlocks), cidrBlock -> cidrBlock.isInRange(address)); } CidrBlockAuthorisation(); boolean isAuthorised(List<String> cidrBlocks, String address);  }
@Test public void authorised() { assertTrue(underTest.isAuthorised(Arrays.asList("1.2.3.4/32"), "1.2.3.4")); assertTrue(underTest.isAuthorised(Arrays.asList("10.0.0.0/8"), "10.255.255.255")); assertTrue(underTest.isAuthorised(Arrays.asList("10.0.0.0/8"), "10.0.0.0")); }
@Test public void notAuthorised() { assertFalse(underTest.isAuthorised(Arrays.asList("1.2.3.4/24"), "1.2.4.4")); }
@Test public void noCidrBlocksNotAuthorised() { assertFalse(underTest.isAuthorised(Arrays.asList(), "1.2.3.4")); }
@Test public void multipleNotAuthorised() { assertFalse(underTest.isAuthorised(Arrays.asList("1.2.3.4/24", "1.2.4.4/24"), "1.2.5.4")); }
@Test public void multipleFirstAuthorised() { assertTrue(underTest.isAuthorised(Arrays.asList("1.2.3.4/24", "1.2.4.4/24"), "1.2.3.4")); }
@Test public void multipleSecondAuthorised() { assertTrue(underTest.isAuthorised(Arrays.asList("1.2.3.4/24", "1.2.4.4/24"), "1.2.4.4")); }