@Test public void testFind() { task = new Task(); dao.insert(task); // verify task was created assertNotNull(task.getId()); // find the added task Task found = (Task) dao.find(task.getId()); assertEquals(task, found); }
@Test public void testFindAll() { Task a = new Task(); Task b = new Task(); dao.insert(a); dao.insert(b); List<Task> list; list = dao.findAll(); assertTrue(list.size() >= 2); assertTrue(list.contains(a)); assertTrue(list.contains(b)); }
@Test public void testDelete() { task = new Task(); dao.insert(task); Long id = task.getId(); // verify task was created assertNotNull(id); // delete the task dao.delete(task); // try to find it by id Task t = dao.find(id); // verify task was not found assertNull(t); }
@Test public void testInsert() { Project project = new Project(1l); task = new Task(project); dao.insert(task); assertNotNull(task.getId()); }
@Test public void testUpdate() { task = new Task(); dao.insert(task); Long id = task.getId(); // modify the task String desc = "new description"; task.setDescription(desc); int duration = 1; task.setDuration(duration); dao.merge(task); // test update Task t = (Task) dao.find(id); assertEquals(desc, t.getDescription()); assertEquals(duration, t.getDuration()); }
@BeforeClass public static void setUpClass() { dao = new TaskDAO(); em = HibernateUtil.getEntityManager(); dao.setEntityManager(em); }