void testModifyEmployee() { Department department1 = this.new Department(); Department department2 = this.new Department(); Employee employee1 = new Employee(); Employee employee2 = new Employee(); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertNull(employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); employee1.setDepartment(department1); AssociationTests.assertCollection(department1.getEmployees(), employee1); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertEquals(department1, employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); employee2.setDepartment(department1); AssociationTests.assertCollection(department1.getEmployees(), employee1, employee2); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertEquals(department1, employee1.getDepartment()); Assert.assertEquals(department1, employee2.getDepartment()); employee1.setDepartment(department2); AssociationTests.assertCollection(department1.getEmployees(), employee2); AssociationTests.assertCollection(department2.getEmployees(), employee1); Assert.assertEquals(department2, employee1.getDepartment()); Assert.assertEquals(department1, employee2.getDepartment()); employee2.setDepartment(department2); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees(), employee1, employee2); Assert.assertEquals(department2, employee1.getDepartment()); Assert.assertEquals(department2, employee2.getDepartment()); employee2.setDepartment(null); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees(), employee1); Assert.assertEquals(department2, employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); employee1.setDepartment(null); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertNull(employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); }
void testModifyDepartment() { Department department1 = this.new Department(); Department department2 = this.new Department(); Employee employee1 = new Employee(); Employee employee2 = new Employee(); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertNull(employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); department1.getEmployees().add(employee1); AssociationTests.assertCollection(department1.getEmployees(), employee1); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertEquals(department1, employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); department1.getEmployees().add(employee2); AssociationTests.assertCollection(department1.getEmployees(), employee1, employee2); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertEquals(department1, employee1.getDepartment()); Assert.assertEquals(department1, employee2.getDepartment()); department2.getEmployees().add(employee1); AssociationTests.assertCollection(department1.getEmployees(), employee2); AssociationTests.assertCollection(department2.getEmployees(), employee1); Assert.assertEquals(department2, employee1.getDepartment()); Assert.assertEquals(department1, employee2.getDepartment()); department2.getEmployees().add(employee2); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees(), employee1, employee2); Assert.assertEquals(department2, employee1.getDepartment()); Assert.assertEquals(department2, employee2.getDepartment()); department2.getEmployees().remove(department2.getEmployees().iterator().next()); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees(), employee2); Assert.assertNull(employee1.getDepartment()); Assert.assertEquals(department2, employee2.getDepartment()); department2.getEmployees().remove(department2.getEmployees().iterator().next()); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertNull(employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); }