### Question:
UrlValidator implements ConstraintValidator<ValidUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (value == null) { return true; } if (value.isEmpty()) { ValidatorUtil.addConstraintViolation(context, "URL may not be empty"); return false; } long validatorOptions = ALLOW_ALL_SCHEMES + ALLOW_LOCAL_URLS + NO_FRAGMENTS; org.apache.commons.validator.routines.UrlValidator commonsValidator = new org.apache.commons.validator.routines.UrlValidator(validatorOptions); if (!commonsValidator.isValid(value)) { ValidatorUtil.addConstraintViolation(context, value + " is not a valid URL"); return false; } return true; }  @Override boolean isValid(String value, ConstraintValidatorContext context);  }### Answer:
@Test public void testValid() { assertTrue(underTest.isValid("https: verify(context, never()).buildConstraintViolationWithTemplate(any(String.class)); }
@Test public void testLocalUrlIsValid() { assertTrue(underTest.isValid("http: verify(context, never()).buildConstraintViolationWithTemplate(any(String.class)); }
@Test public void testInvalid() { assertFalse(underTest.isValid("foo", context)); verify(context).buildConstraintViolationWithTemplate(any(String.class)); }
@Test public void testNullIsValid() { assertTrue(underTest.isValid(null, context)); verify(context, never()).buildConstraintViolationWithTemplate(any(String.class)); }
@Test public void testEmptyIsInvalid() { assertFalse(underTest.isValid("", context)); verify(context).buildConstraintViolationWithTemplate(any(String.class)); }