### Question:
VoidRadiologyReportRequestValidator implements Validator { @Override public void validate(Object obj, Errors errors) { final VoidRadiologyReportRequest voidRadiologyReportRequest = (VoidRadiologyReportRequest) obj; if (voidRadiologyReportRequest == null) { errors.reject("error.general"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "voidReason", "error.null"); } }  @Override boolean supports(Class clazz); @Override void validate(Object obj, Errors errors);  }### Answer:
@Test public void shouldFailValidationIfDiscontinuationOrderRequestIsNull() throws Exception { Errors errors = new BindException(voidRadiologyReportRequest, "voidRadiologyReportRequest"); voidRadiologyReportRequestValidator.validate(null, errors); assertTrue(errors.hasErrors()); assertThat(errors.getAllErrors() .size(), is(1)); assertThat((errors.getAllErrors()).get(0) .getCode(), is("error.general")); }
@Test public void shouldFailValidationIfVoidReasonNonCodedIsNull() throws Exception { voidRadiologyReportRequest.setVoidReason(null); Errors errors = new BindException(voidRadiologyReportRequest, "voidRadiologyReportRequest"); voidRadiologyReportRequestValidator.validate(voidRadiologyReportRequest, errors); assertTrue(errors.hasErrors()); assertThat(errors.getAllErrors() .size(), is(1)); assertTrue(errors.hasFieldErrors("voidReason")); voidRadiologyReportRequest.setVoidReason(""); errors = new BindException(voidRadiologyReportRequest, "voidRadiologyReportRequest"); voidRadiologyReportRequestValidator.validate(voidRadiologyReportRequest, errors); assertTrue(errors.hasErrors()); assertThat(errors.getAllErrors() .size(), is(1)); assertTrue(errors.hasFieldErrors("voidReason")); voidRadiologyReportRequest.setVoidReason(" "); errors = new BindException(voidRadiologyReportRequest, "voidRadiologyReportRequest"); voidRadiologyReportRequestValidator.validate(voidRadiologyReportRequest, errors); assertTrue(errors.hasErrors()); assertThat(errors.getAllErrors() .size(), is(1)); assertTrue(errors.hasFieldErrors("voidReason")); }
@Test public void shouldPassValidationIfAllFieldsAreCorrect() throws Exception { Errors errors = new BindException(voidRadiologyReportRequest, "voidRadiologyReportRequest"); voidRadiologyReportRequestValidator.validate(voidRadiologyReportRequest, errors); assertFalse(errors.hasErrors()); }