CidrListValidator implements ConstraintValidator<CidrList, List<String>> { @Override public boolean isValid(List<String> cidrList, ConstraintValidatorContext context) { if (cidrList == null || cidrList.isEmpty()) { return true; } for (String cidr : cidrList) { if (!isValidCidr(cidr)) { return false; } } return true; }  @Override void initialize(CidrList target); @Override boolean isValid(List<String> cidrList, ConstraintValidatorContext context);  }
@Test public void testEmptyCidrList() { assertTrue(validator.isValid(Collections.<String>emptyList(), null)); }
@Test public void testValidCidrList() { List<String> validCidrList = ImmutableList.of( "198.51.100.1/24", "198.51.100.0/22", "2001:db8::/48", "198.51.100.1", "2001:db8:0:0:0:0:0:0"); assertTrue(validator.isValid(validCidrList, null)); }
@Test public void testInvalidCidrList() { List<String> invalidCidrList = ImmutableList.of( "aaa", "198.2", "198.2.4/24", "198.2.4.1/60"); assertFalse(validator.isValid(invalidCidrList, null)); }