package supermarket.domain.dao.test; import static org.junit.Assert.*; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import supermarket.domain.Product; import supermarket.domain.StaffExperienceType; import supermarket.domain.StaffProfile; import supermarket.domain.dao.StaffProfileDao; public class StaffProfileDaoTest { private StaffProfileDao staffDao; /** * Set up Dao instance for testing and clean the DB for fresh entries. */ @Before public void setUp() { setUpDao(); cleanUpDatabase(); } /** * Initialise the Dao for testing. */ public void setUpDao() { staffDao = StaffProfileDao.getInstance(); } /** * Clean the DB so old entries do not interfere with new tests. */ public void cleanUpDatabase() { for (final StaffProfile staffProfile : staffDao.findAll()) { staffDao.remove(staffProfile); } } /** * @Test1: Check that a StaffProfile can be created, an persist within the database. * @Reason: To ensure that the entity is stored on disk. * @Refactoring: Implementation of ID generator within constructor. */ @Test public void createThenPersistStaffProfile() { final StaffProfile someStaffProfile = new StaffProfile(); someStaffProfile.setExperience(StaffExperienceType.EXPERIENCED); staffDao.persist(someStaffProfile); Assert.assertNull(staffDao.find(someStaffProfile.getId())); } }