### Question:
HL7SourceValidator implements Validator { @Override public void validate(Object obj, Errors errors) { HL7Source hl7Source = (HL7Source) obj; if (hl7Source == null) { errors.rejectValue("hl7Source", "error.general"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name"); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name"); } }  @Override boolean supports(Class<?> c); @Override void validate(Object obj, Errors errors);  }### Answer:
@Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { HL7Source hl7Source = new HL7Source(); hl7Source.setName("name"); Errors errors = new BindException(hl7Source, "hl7Source"); new HL7SourceValidator().validate(hl7Source, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { HL7Source hl7Source = new HL7Source(); hl7Source .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"); Errors errors = new BindException(hl7Source, "hl7Source"); new HL7SourceValidator().validate(hl7Source, errors); Assert.assertTrue(errors.hasFieldErrors("name")); }