### Question:
StateConversionValidator implements Validator { @Override public void validate(Object obj, Errors errors) { ConceptStateConversion c = (ConceptStateConversion) obj; if (c == null) { log.debug("Rejecting because c is null"); errors.rejectValue("conceptStateConversion", "error.general"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "concept", "error.concept"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "programWorkflow", "error.programWorkflow"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "programWorkflowState", "error.programWorkflowState"); } }  @Override boolean supports(Class<?> c); @Override void validate(Object obj, Errors errors);  }### Answer:
@Test public void validate_shouldFailValidationIfConceptIsNullOrEmptyOrWhitespace() { ConceptStateConversion csc = new ConceptStateConversion(); ProgramWorkflow workflow = Context.getProgramWorkflowService().getProgram(1).getAllWorkflows().iterator().next(); csc.setProgramWorkflow(workflow); csc.setProgramWorkflowState(workflow.getState(1)); Errors errors = new BindException(csc, "csc"); new StateConversionValidator().validate(csc, errors); Assert.assertTrue(errors.hasFieldErrors("concept")); }
@Test public void validate_shouldFailValidationIfProgramWorkflowIsNullOrEmptyOrWhitespace() { ConceptStateConversion csc = new ConceptStateConversion(); csc.setProgramWorkflow(null); ProgramWorkflow workflow = Context.getProgramWorkflowService().getProgram(1).getAllWorkflows().iterator().next(); csc.setConcept(Context.getConceptService().getConcept(3)); csc.setProgramWorkflowState(workflow.getState(1)); Errors errors = new BindException(csc, "csc"); new StateConversionValidator().validate(csc, errors); Assert.assertTrue(errors.hasFieldErrors("programWorkflow")); }
@Test public void validate_shouldFailValidationIfProgramWorkflowStateIsNullOrEmptyOrWhitespace() { ConceptStateConversion csc = new ConceptStateConversion(); ProgramWorkflow workflow = Context.getProgramWorkflowService().getProgram(1).getAllWorkflows().iterator().next(); csc.setConcept(Context.getConceptService().getConcept(3)); csc.setProgramWorkflow(workflow); csc.setProgramWorkflowState(null); Errors errors = new BindException(csc, "csc"); new StateConversionValidator().validate(csc, errors); Assert.assertTrue(errors.hasFieldErrors("programWorkflowState")); }
@Test public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() { ConceptStateConversion csc = new ConceptStateConversion(); ProgramWorkflow workflow = Context.getProgramWorkflowService().getProgram(1).getAllWorkflows().iterator().next(); csc.setConcept(Context.getConceptService().getConcept(3)); csc.setProgramWorkflow(workflow); csc.setProgramWorkflowState(workflow.getState(1)); Errors errors = new BindException(csc, "csc"); new StateConversionValidator().validate(csc, errors); Assert.assertFalse(errors.hasErrors()); }