@Test public void testUpdate() throws Exception { Department preUpdatedDepartment = departmentDAO.get(did); Employee employee3 = new Employee("UPDATE", "UPDATE", "XXX-XXX-XXX", 40); preUpdatedDepartment.setDepartmentName("UPDATE"); preUpdatedDepartment.getEmployees().add(employee3); departmentDAO.saveOrUpdate(preUpdatedDepartment); employee3.setDepartment(department); Department updatedDepartment = departmentDAO.get(did); eid3 = (Long) employeeDAO.saveOrUpdate(employee3); Employee updatedEmployee = employeeDAO.get(eid3); assertEquals( "Add method failed: wrong department name", preUpdatedDepartment.getDepartmentName(), updatedDepartment.getDepartmentName()); assertEquals( "Add method failed: wrong employees", preUpdatedDepartment.getEmployees().size(), updatedDepartment.getEmployees().size()); assertEquals( "Add method failed: wrong department", employee3.getDepartment(), updatedEmployee.getDepartment()); }
@Test public void testAdd() throws Exception { department.setDepartmentId(did); Employee addedEmployee1 = employeeDAO.get(eid1); Employee addedEmployee2 = employeeDAO.get(eid2); Department addedDepartment = departmentDAO.get(did); assertEquals( "Add method failed: wrong department name", addedDepartment.getDepartmentName(), department.getDepartmentName()); assertEquals( "Add method failed: wrong employees", addedDepartment.getEmployees().size(), department.getEmployees().size()); assertEquals( "Add method failed: wrong department", addedEmployee1.getDepartment(), employee1.getDepartment()); assertEquals( "Add method failed: wrong department", addedEmployee2.getDepartment(), employee2.getDepartment()); }