### Question:
PatientIdentifierValidator implements Validator { @Override public void validate(Object obj, Errors errors) { PatientIdentifier pi = (PatientIdentifier) obj; try { validateIdentifier(pi); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "identifier", "voidReason"); } catch (Exception e) { errors.reject(e.getMessage()); } }  @Override boolean supports(Class<?> c); @Override void validate(Object obj, Errors errors); static void validateIdentifier(PatientIdentifier pi); static void validateIdentifier(String identifier, PatientIdentifierType pit); static void checkIdentifierAgainstFormat(String identifier, String format, String formatDescription); static void checkIdentifierAgainstValidator(String identifier, IdentifierValidator validator);  }### Answer:
@Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { PatientIdentifier pi = new PatientIdentifier("1TU-8", new PatientIdentifierType(1), null); PatientIdentifierType idType = pi.getIdentifierType(); idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED); pi.setVoidReason("voidReason"); Errors errors = new BindException(pi, "pi"); new PatientIdentifierValidator().validate(pi, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { PatientIdentifier pi = new PatientIdentifier("too long text too long text too long text too long text", new PatientIdentifierType(1), null); PatientIdentifierType idType = pi.getIdentifierType(); idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED); pi .setVoidReason("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(pi, "pi"); new PatientIdentifierValidator().validate(pi, errors); Assert.assertTrue(errors.hasFieldErrors("identifier")); Assert.assertTrue(errors.hasFieldErrors("voidReason")); }