/** @see {@link CohortService#voidCohort(Cohort,String)} */
  @Test
  @Verifies(value = "should fail if reason is null", method = "voidCohort(Cohort,String)")
  public void voidCohort_shouldFailIfReasonIsNull() throws Exception {
    executeDataSet(COHORT_XML);

    // Get a non-voided, valid Cohort and try to void it with a null reason
    Cohort exampleCohort = service.getCohort("Example Cohort");
    assertNotNull(exampleCohort);
    assertFalse(exampleCohort.isVoided());

    try {
      service.voidCohort(exampleCohort, null);
      Assert.fail("voidCohort should fail with exception if reason is null.");
    } catch (Exception e) {
    }

    // Now get the Cohort and try to void it with an empty reason
    exampleCohort = service.getCohort("Example Cohort");
    assertNotNull(exampleCohort);
    assertFalse(exampleCohort.isVoided());

    try {
      service.voidCohort(exampleCohort, "");
      Assert.fail("voidCohort should fail with exception if reason is empty");
    } catch (Exception e) {
    }
  }
  /** @see {@link CohortService#addPatientToCohort(Cohort,Patient)} */
  @Test
  @Verifies(
      value = "should add a patient and save the cohort",
      method = "addPatientToCohort(Cohort,Patient)")
  public void addPatientToCohort_shouldAddAPatientAndSaveTheCohort() throws Exception {
    executeDataSet(COHORT_XML);

    // make a patient, add it using the method
    Patient patientToAdd = new Patient(4);
    service.addPatientToCohort(service.getCohort(2), patientToAdd);
    // proof of "save the cohort": see if the patient is in the cohort
    assertTrue(service.getCohort(2).contains(4));
  }
  /**
   * @verifies {@link CohortService#removePatientFromCohort(Cohort,Patient)} test = should save
   *     cohort after removing patient
   */
  @Test
  @Verifies(
      value = "should save cohort after removing patient",
      method = "removePatientFromCohort(Cohort,Patient)")
  public void removePatientFromCohort_shouldSaveCohortAfterRemovingPatient() throws Exception {
    executeDataSet(COHORT_XML);

    // make a patient, add it using the method
    Patient patientToAddThenRemove = new Patient(4);
    service.addPatientToCohort(service.getCohort(2), patientToAddThenRemove);
    assertTrue(service.getCohort(2).contains(patientToAddThenRemove));
    service.removePatientFromCohort(service.getCohort(2), patientToAddThenRemove);
    assertFalse(service.getCohort(2).contains(patientToAddThenRemove));
  }
  /** @see {@link CohortService#saveCohort(Cohort)} */
  @Test
  @Verifies(value = "should update an existing cohort", method = "saveCohort(Cohort)")
  public void saveCohort_shouldUpdateAnExistingCohort() throws Exception {
    executeDataSet(COHORT_XML);

    // get and modify a cohort in the  data set
    String modifiedCohortDescription = "This description has been modified in a test";
    Cohort cohortToModify = service.getCohort(2);
    cohortToModify.setDescription(modifiedCohortDescription);

    // save the modified cohort back to the data set, see if the modification is there
    service.saveCohort(cohortToModify);
    assertTrue(service.getCohort(2).getDescription().equals(modifiedCohortDescription));
  }
  /** @see {@link CohortService#getCohortsContainingPatient(Patient)} */
  @Test
  @Verifies(
      value = "should return cohorts that have given patient",
      method = "getCohortsContainingPatient(Patient)")
  public void getCohortsContainingPatient_shouldReturnCohortsThatHaveGivenPatient()
      throws Exception {
    executeDataSet(COHORT_XML);

    Patient patientToAdd = new Patient(4);
    service.addPatientToCohort(service.getCohort(2), patientToAdd);
    assertTrue(service.getCohort(2).contains(patientToAdd));

    List<Cohort> cohortsWithGivenPatient = service.getCohortsContainingPatient(patientToAdd);
    assertTrue(cohortsWithGivenPatient.contains(service.getCohort(2)));
  }
  /** @see {@link CohortService#getCohort(String)} */
  @Test
  @Verifies(value = "should get cohort given a name", method = "getCohort(String)")
  public void getCohort_shouldGetCohortGivenAName() throws Exception {
    executeDataSet(COHORT_XML);

    Cohort cohortToGet = service.getCohort("Example Cohort");
    assertTrue(cohortToGet.getCohortId() == 2);
  }
  /** @see {@link CohortService#getCohort(Integer)} */
  @Test
  @Verifies(value = "should get cohort by id", method = "getCohort(Integer)")
  public void getCohort_shouldGetCohortById() throws Exception {
    executeDataSet(COHORT_XML);

    Cohort cohortToGet = service.getCohort(2);
    assertNotNull(cohortToGet);
    assertTrue(cohortToGet.getCohortId() == 2);
  }
  /** @see {@link CohortService#addPatientToCohort(Cohort,Patient)} */
  @Test
  @Verifies(
      value = "should not fail if cohort already contains patient",
      method = "addPatientToCohort(Cohort,Patient)")
  public void addPatientToCohort_shouldNotFailIfCohortAlreadyContainsPatient() throws Exception {
    executeDataSet(COHORT_XML);

    // make a patient, add it using the method
    Patient patientToAdd = new Patient(4);
    service.addPatientToCohort(service.getCohort(2), patientToAdd);
    assertTrue(service.getCohort(2).contains(4));

    // do it again to see if it fails
    try {
      service.addPatientToCohort(service.getCohort(2), patientToAdd);
    } catch (Exception e) {
      Assert.fail("addPatientToCohort(Cohort,Patient) fails when cohort already contains patient.");
    }
  }
  /**
   * @verifies {@link CohortService#removePatientFromCohort(Cohort,Patient)} test = should not fail
   *     if cohort does not contain patient
   */
  @Test
  @Verifies(
      value = "should not fail if cohort doesn't contain patient",
      method = "removePatientFromCohort(Cohort,Patient)")
  public void removePatientFromCohort_shouldNotFailIfCohortDoesNotContainPatient()
      throws Exception {
    executeDataSet(COHORT_XML);

    // make a patient
    Patient patientToAddThenRemove = new Patient(4);
    // verify that the patient is not already in the Cohort
    assertFalse(service.getCohort(2).contains(patientToAddThenRemove));
    // try to remove it from the cohort without failing
    try {
      service.removePatientFromCohort(service.getCohort(2), patientToAddThenRemove);
    } catch (Exception e) {
      Assert.fail(
          "removePatientFromCohort(Cohort,Patient) should not fail if cohort doesn't contain patient");
    }
  }
  /** @see {@link CohortService#getCohortsContainingPatient(Patient)} */
  @Test
  @Verifies(
      value = "should not return voided cohorts",
      method = "getCohortsContainingPatient(Patient)")
  public void getCohortsContainingPatient_shouldNotReturnVoidedCohorts() throws Exception {
    executeDataSet(COHORT_XML);

    // make sure we have two cohorts, the first of which is voided
    assertTrue(service.getCohort(1).isVoided());
    assertFalse(service.getCohort(2).isVoided());

    // add a patient to both cohorts
    Patient patientToAdd = new Patient(4);
    service.addPatientToCohort(service.getCohort(1), patientToAdd);
    service.addPatientToCohort(service.getCohort(2), patientToAdd);
    assertTrue(service.getCohort(1).contains(patientToAdd));
    assertTrue(service.getCohort(2).contains(patientToAdd));

    // call the method and it should not return the voided cohort
    List<Cohort> cohortsWithPatientAdded = service.getCohortsContainingPatient(patientToAdd);
    assertNotNull(cohortsWithPatientAdded);
    assertFalse(cohortsWithPatientAdded.contains(service.getCohort(1)));
  }
  /** @see {@link CohortService#getCohort(String)} */
  @Test
  @Verifies(value = "should only get non voided cohorts by name", method = "getCohort(String)")
  public void getCohort_shouldOnlyGetNonVoidedCohortsByName() throws Exception {
    executeDataSet(COHORT_XML);

    // make sure we have two cohorts with the same name and the first is voided
    List<Cohort> allCohorts = service.getAllCohorts(true);
    assertNotNull(allCohorts);
    assertEquals(2, allCohorts.size());
    assertTrue(allCohorts.get(0).isVoided());
    assertFalse(allCohorts.get(1).isVoided());

    // now do the actual test: getCohort by name and expect a non voided cohort
    Cohort exampleCohort = service.getCohort("Example Cohort");
    assertNotNull(exampleCohort);
    assertEquals(2, exampleCohort.size());
    assertFalse(exampleCohort.isVoided());
  }
  /** @see {@link CohortService#getCohort(String)} */
  @Test
  @Verifies(
      value = "should get the nonvoided cohort if two exist with same name",
      method = "getCohort(String)")
  public void getCohort_shouldGetTheNonvoidedCohortIfTwoExistWithSameName() throws Exception {
    executeDataSet(COHORT_XML);

    // check to see if both cohorts have the same name and if one is voided
    List<Cohort> allCohorts = service.getAllCohorts(true);
    assertNotNull(allCohorts);
    assertEquals(allCohorts.get(0).getName(), allCohorts.get(1).getName());
    assertTrue(allCohorts.get(0).isVoided());
    assertFalse(allCohorts.get(1).isVoided());
    // the non-voided cohort should have an id of 2
    assertTrue(allCohorts.get(1).getCohortId() == 2);

    // ask for the cohort by name
    Cohort cohortToGet = service.getCohort("Example Cohort");
    // see if the non-voided one got returned
    assertTrue(cohortToGet.getCohortId() == 2);
  }