### Question:
ProviderAttributeTypeValidator extends BaseAttributeTypeValidator<ProviderAttributeType> { @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() { ProviderAttributeType type = new ProviderAttributeType(); type.setName("name"); type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype"); type.setDescription("description"); type.setRetireReason("retireReason"); Errors errors = new BindException(type, "type"); new ProviderAttributeTypeValidator().validate(type, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { ProviderAttributeType type = new ProviderAttributeType(); type .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"); type .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"); type.setDescription(new String(new char[655555])); type .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"); type .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(type, "type"); new ProviderAttributeTypeValidator().validate(type, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("datatypeClassname")); Assert.assertTrue(errors.hasFieldErrors("description")); Assert.assertTrue(errors.hasFieldErrors("preferredHandlerClassname")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); }