@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); }
@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); }
@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); }
@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); }