コード例 #1
0
  @Test
  public void findByUnknownId() {
    when(dao.findById(2)).thenReturn(null);

    Employment result = service.findById(2);

    verify(dao).findById(2);
    assertNull(result);
  }
コード例 #2
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);
  }
コード例 #3
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());
  }
コード例 #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);
  }