### Question:
VisitTypeValidator implements Validator { @Override public void validate(Object obj, Errors errors) { VisitType visitType = (VisitType) obj; if (visitType == null) { errors.rejectValue("visitType", "error.general"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name"); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason"); } }  @Override boolean supports(Class<?> c); @Override void validate(Object obj, Errors errors);  }### Answer:
@Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { VisitType visitType = new VisitType(); visitType.setName("name"); visitType.setDescription("some text"); visitType.setRetireReason("some text"); Errors errors = new BindException(visitType, "visitType"); new VisitTypeValidator().validate(visitType, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { VisitType visitType = new VisitType(); visitType .setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); visitType .setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); visitType .setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); Errors errors = new BindException(visitType, "visitType"); new VisitTypeValidator().validate(visitType, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("description")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); }