@Test public void valid() { final ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); final boolean result = urlValidator.isValid("http: assertThat(result).isTrue(); verifyNoMoreInteractions(context); }
@Override public boolean isValid(String value, ConstraintValidatorContext context) { try { new URL(value); return true; } catch (MalformedURLException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("Invalid URL: %s", e.getMessage())) .addConstraintViolation(); return false; } }
UrlValidator implements ConstraintValidator<ValidUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { try { new URL(value); return true; } catch (MalformedURLException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("Invalid URL: %s", e.getMessage())) .addConstraintViolation(); return false; } } }
UrlValidator implements ConstraintValidator<ValidUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { try { new URL(value); return true; } catch (MalformedURLException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("Invalid URL: %s", e.getMessage())) .addConstraintViolation(); return false; } }  }
UrlValidator implements ConstraintValidator<ValidUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { try { new URL(value); return true; } catch (MalformedURLException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("Invalid URL: %s", e.getMessage())) .addConstraintViolation(); return false; } }  @Override boolean isValid(String value, ConstraintValidatorContext context); }
UrlValidator implements ConstraintValidator<ValidUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { try { new URL(value); return true; } catch (MalformedURLException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("Invalid URL: %s", e.getMessage())) .addConstraintViolation(); return false; } }  @Override boolean isValid(String value, ConstraintValidatorContext context);  }