コード例 #1
0
  @Test
  public void findById() {
    Employment employment = EmploymentDaoJpaTest.createEmployment(1, "Test Employment One");

    when(dao.findById(1)).thenReturn(employment);

    Employment employmentTest = service.findById(1);

    verify(dao).findById(1);
    assertSame(employment, employmentTest);
  }
コード例 #2
0
  @Test
  public void findAll() {
    List<Employment> employments = EmploymentDaoJpaTest.createEmployments();

    when(dao.findAll()).thenReturn(employments);

    Collection<Employment> result = service.findAll();

    verify(dao).findAll();
    assertEquals(3, result.size());
  }
コード例 #3
0
  @Test
  public void remove() throws DaoStoreException {

    Employment employment = EmploymentDaoJpaTest.createEmployment(1, "test user");

    doNothing().when(dao).remove(employment);

    service.remove(employment);

    verify(dao).remove(employment);
  }
コード例 #4
0
  @Test
  public void persist() throws DaoStoreException {

    Employment employment = EmploymentDaoJpaTest.createEmployment(1, "test user");

    when(dao.persist(employment)).thenReturn(employment);

    Employment actual = service.persist(employment);

    verify(dao).persist(employment);
    assertSame(employment, actual);
  }
コード例 #5
0
  @Test
  public void removeDaoStoreException() throws DaoStoreException {
    Employment employment = EmploymentDaoJpaTest.createEmployment(1, "test user");
    IllegalStateException illegalStateException = new IllegalStateException("");

    doThrow(illegalStateException).when(dao).remove(employment);

    try {
      service.remove(employment);
      fail("Should have thrown an IllegalStateException");
    } catch (Exception e) {
      assertSame(illegalStateException, e);
    }
    verify(dao).remove(employment);
  }