/**
   * Test to check we can remove a candidate from the database.
   *
   * @throws DaoStoreException
   */
  @Test
  public void testRemove() throws DaoStoreException {
    CandidateDaoJpa dao = new CandidateDaoJpa();
    dao.setEntityManager(this.em);

    Collection<Candidate> found = dao.findAll();
    int initial = found.size();

    // remove the candidate
    Candidate candidate = dao.findById(new Integer(1));
    dao.remove(candidate);

    found = dao.findAll();
    int after = found.size();

    assertEquals("candidate size should have decreased", initial - 1, after);
  }
  /** A simple test to check we can retrieve all candidates. */
  @Test
  public void testFindByAll() {
    CandidateDaoJpa dao = new CandidateDaoJpa();
    dao.setEntityManager(this.em);

    Collection<Candidate> found = dao.findAll();

    assertEquals("candidate should have 3 entries", found.size(), 3);
  }
  /**
   * Test to check we can add a simple candidate to the database and then retrieve it back. Simple
   * candidate means it has no relationships.
   *
   * @throws DaoStoreException
   */
  @Test
  public void testPersit() throws DaoStoreException {
    CandidateDaoJpa dao = new CandidateDaoJpa();
    dao.setEntityManager(this.em);

    Collection<Candidate> found = dao.findAll();
    int initial = found.size();

    Candidate candidate = new Candidate();
    candidate.setName("test candidate");
    candidate.setAddress("test address");
    candidate.setEmail("*****@*****.**");

    dao.persist(candidate);
    found = dao.findAll();
    int after = found.size();

    assertEquals("candidate size should have increased", initial + 1, after);
  }