### Question:
LocationTagValidator implements Validator { @Override public void validate(Object target, Errors errors) { if (target != null) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "LocationTag.error.name.required"); ValidateUtil.validateFieldLengths(errors, target.getClass(), "name", "description", "retireReason"); } }  @Override boolean supports(Class<?> c); @Override void validate(Object target, Errors errors);  }### Answer:
@Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { LocationTag locationTag = new LocationTag(); locationTag.setName("name"); locationTag.setDescription("description"); locationTag.setRetireReason("retireReason"); Errors errors = new BindException(locationTag, "locationTag"); new LocationTagValidator().validate(locationTag, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { LocationTag locationTag = new LocationTag(); locationTag .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"); locationTag .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"); locationTag .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(locationTag, "location"); new LocationTagValidator().validate(locationTag, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("description")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); }