### Question:
RequireNameValidator implements Validator { @Override public void validate(Object o, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name"); }  @Override boolean supports(Class<?> c); @Override void validate(Object o, Errors errors);  }### Answer:
@Test public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() { EncounterRole role = new EncounterRole(); role.setName(null); role.setDescription(":("); Errors errors = new BindException(role, "type"); new RequireNameValidator().validate(role, errors); Assert.assertTrue(errors.hasFieldErrors("name")); role.setName(""); errors = new BindException(role, "type"); new RequireNameValidator().validate(role, errors); Assert.assertTrue(errors.hasFieldErrors("name")); role.setName(" "); errors = new BindException(role, "type"); new RequireNameValidator().validate(role, errors); Assert.assertTrue(errors.hasFieldErrors("name")); }
@Test public void validate_shouldPassValidationIfNameHasProperValue() { EncounterRole role = new EncounterRole(); role.setName("restraining"); Errors errors = new BindException(role, "type"); new RequireNameValidator().validate(role, errors); Assert.assertFalse(errors.hasErrors()); }