### Question:
VisitAttributeTypeValidator extends BaseAttributeTypeValidator<VisitAttributeType> { @Override public void validate(Object obj, Errors errors) { if (obj != null) { super.validate(obj, errors); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "datatypeClassname", "preferredHandlerClassname", "retireReason"); } }  @Override boolean supports(Class<?> c); @Override void validate(Object obj, Errors errors);  }### Answer:
@Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { VisitAttributeType visitAttributeType = new VisitAttributeType(); visitAttributeType.setName("name"); visitAttributeType.setMinOccurs(1); visitAttributeType.setDatatypeConfig("[a-z]+"); visitAttributeType.setDatatypeClassname(RegexValidatedTextDatatype.class.getName()); visitAttributeType.setDescription("some text"); visitAttributeType.setRetireReason("some text"); Errors errors = new BindException(visitAttributeType, "visitAttributeType"); new VisitAttributeTypeValidator().validate(visitAttributeType, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { VisitAttributeType visitAttributeType = new VisitAttributeType(); visitAttributeType .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"); visitAttributeType.setMinOccurs(1); visitAttributeType.setDatatypeConfig("[a-z]+"); visitAttributeType .setDatatypeClassname("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"); visitAttributeType.setDescription(new String(new char[66000])); visitAttributeType .setPreferredHandlerClassname("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"); visitAttributeType .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(visitAttributeType, "visitAttributeType"); new VisitAttributeTypeValidator().validate(visitAttributeType, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("description")); Assert.assertTrue(errors.hasFieldErrors("datatypeClassname")); Assert.assertTrue(errors.hasFieldErrors("preferredHandlerClassname")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); }