NullableDomainOrIPValidator implements ConstraintValidator<NullableDomainOrIP, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) { return true; } return validator.isValid(value, context); } @Inject  NullableDomainOrIPValidator(); @Override void initialize(NullableDomainOrIP constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context);  }
@Test public void testNull() { Assert.assertTrue(validator.isValid(null, context)); }
@Test public void testValidIpAddress() { Assert.assertTrue(validator.isValid("192.168.1.1", context)); }
@Test public void testInvalidIpAddress() { Assert.assertFalse(validator.isValid("192.168.1.500", context)); }
@Test public void testValidDomainAddress() throws UnknownHostException { Assert.assertTrue(validator.isValid("www.google.com", context)); }
@Test public void testInvalidHostName() { Assert.assertFalse(validator.isValid("fakename", context)); }