### Question:
ValidateUtil { public static void validateFieldLengths(Errors errors, Class<?> aClass, String... fields) { if (disableValidation) { return; } Assert.notNull(errors, "Errors object must not be null"); for (String field : fields) { Object value = errors.getFieldValue(field); if (value == null || !(value instanceof String)) { continue; } int length = Context.getAdministrationService().getMaximumPropertyLength((Class<? extends OpenmrsObject>) aClass, field); if (length == -1) { return; } if (((String) value).length() > length) { errors.rejectValue(field, "error.exceededMaxLengthOfField", new Object[] { length }, null); } } } private  ValidateUtil(); static void validate(Object obj); static void validate(Object obj, Errors errors); static void validateFieldLengths(Errors errors, Class<?> aClass, String... fields); static Boolean getDisableValidation(); static void setDisableValidation(Boolean disableValidation);  }### Answer:
@Test public void validateFieldLength_shouldRejectValueWhenNameIsToLong() { PatientIdentifierType patientIdentifierType = new PatientIdentifierType(); patientIdentifierType.setName("asdfghjkl asdfghjkl asdfghjkl asdfghjkl asdfghjkl xx"); BindException errors = new BindException(patientIdentifierType, "patientIdentifierType"); ValidateUtil.validateFieldLengths(errors, PatientIdentifierType.class, "name"); assertTrue(errors.hasFieldErrors("name")); }
@Test public void validateFieldLength_shouldNotRejectValueWhenNameIsEqualMax() { PatientIdentifierType patientIdentifierType = new PatientIdentifierType(); patientIdentifierType.setName("asdfghjkl asdfghjkl asdfghjkl asdfghjkl asdfghjkl "); BindException errors = new BindException(patientIdentifierType, "patientIdentifierType"); ValidateUtil.validateFieldLengths(errors, PatientIdentifierType.class, "name"); assertFalse(errors.hasFieldErrors("name")); }