コード例 #1
0
ファイル: ModelTest.java プロジェクト: ChenArthur/babyfish
  @Test
  public void testChangeKeyByDepartment() {

    Department department = new Department();
    Employee employee1 = new Employee();
    Employee employee2 = new Employee();
    Employee employee3 = new Employee();
    department.getEmployees().put("I", employee1);
    department.getEmployees().put("II", employee2);
    department.getEmployees().put("III", employee3);
    Utils.assertCollection(department.getEmployees().keySet(), "I", "II", "III");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee2, employee3);
    Assert.assertEquals("I", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("II", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertEquals("III", employee3.getCodeInDepartment());
    Assert.assertEquals(department, employee3.getDepartment());

    department.getEmployees().put("IV", employee2);
    Utils.assertCollection(department.getEmployees().keySet(), "I", "III", "IV");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee3, employee2);
    Assert.assertEquals("I", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("IV", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertEquals("III", employee3.getCodeInDepartment());
    Assert.assertEquals(department, employee3.getDepartment());

    department.getEmployees().put("III", employee1);
    Utils.assertCollection(department.getEmployees().keySet(), "III", "IV");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee2);
    Assert.assertEquals("III", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("IV", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertNull(employee3.getCodeInDepartment());
    Assert.assertNull(employee3.getDepartment());

    department.getEmployees().put("III", employee2);
    Utils.assertCollection(department.getEmployees().keySet(), "III");
    Utils.assertCollection(department.getEmployees().values(), employee2);
    Assert.assertNull(employee1.getCodeInDepartment());
    Assert.assertNull(employee1.getDepartment());
    Assert.assertEquals("III", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertNull(employee3.getCodeInDepartment());
    Assert.assertNull(employee3.getDepartment());
  }
コード例 #2
0
ファイル: ModelTest.java プロジェクト: ChenArthur/babyfish
  @Test
  public void testBatchChangeKeyByDepartment() {
    Department department = new Department();
    Employee employee1 = new Employee();
    Employee employee2 = new Employee();
    Employee employee3 = new Employee();
    department.getEmployees().put("I", employee1);
    department.getEmployees().put("II", employee2);
    department.getEmployees().put("III", employee3);
    Utils.assertCollection(department.getEmployees().keySet(), "I", "II", "III");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee2, employee3);
    Assert.assertEquals("I", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("II", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertEquals("III", employee3.getCodeInDepartment());
    Assert.assertEquals(department, employee3.getDepartment());

    Map<String, Employee> map = new LinkedHashMap<String, Employee>();
    map.put("I", employee1);
    map.put("II", employee1);
    map.put("IV", employee3);
    department.getEmployees().putAll(map);
    Utils.assertCollection(department.getEmployees().keySet(), "II", "IV");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee3);
    Assert.assertEquals("II", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertNull(employee2.getCodeInDepartment());
    Assert.assertNull(employee2.getDepartment());
    Assert.assertEquals("IV", employee3.getCodeInDepartment());
    Assert.assertEquals(department, employee3.getDepartment());
  }
コード例 #3
0
ファイル: ModelTest.java プロジェクト: ChenArthur/babyfish
  @Test
  public void testChangeKeyByEmployee() {

    Department department = new Department();
    Employee employee1 = new Employee();
    Employee employee2 = new Employee();
    Employee employee3 = new Employee();
    department.getEmployees().put("I", employee1);
    department.getEmployees().put("II", employee2);
    department.getEmployees().put("III", employee3);
    Utils.assertCollection(department.getEmployees().keySet(), "I", "II", "III");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee2, employee3);
    Assert.assertEquals("I", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("II", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertEquals("III", employee3.getCodeInDepartment());
    Assert.assertEquals(department, employee3.getDepartment());

    employee2.setCodeInDepartment("IV");
    Utils.assertCollection(department.getEmployees().keySet(), "I", "IV", "III");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee2, employee3);
    Assert.assertEquals("I", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("IV", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertEquals("III", employee3.getCodeInDepartment());
    Assert.assertEquals(department, employee3.getDepartment());

    employee1.setCodeInDepartment("III");
    Utils.assertCollection(department.getEmployees().keySet(), "III", "IV");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee2);
    Assert.assertEquals("III", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("IV", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertNull(employee3.getCodeInDepartment());
    Assert.assertNull(employee3.getDepartment());

    // employee3 is still not a element of the map because it
    // removed from it automatically in the previous step
    employee3.setCodeInDepartment("I");
    Utils.assertCollection(department.getEmployees().keySet(), "III", "IV");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee2);
    Assert.assertEquals("III", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("IV", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertNull(employee3.getCodeInDepartment());
    Assert.assertNull(employee3.getDepartment());

    employee3.setDepartment(department);
    Utils.assertCollection(department.getEmployees().keySet(), "III", "IV", "I");
    Utils.assertCollection(department.getEmployees().values(), employee1, employee2, employee3);
    Assert.assertEquals("III", employee1.getCodeInDepartment());
    Assert.assertEquals(department, employee1.getDepartment());
    Assert.assertEquals("IV", employee2.getCodeInDepartment());
    Assert.assertEquals(department, employee2.getDepartment());
    Assert.assertEquals("I", employee3.getCodeInDepartment());
    Assert.assertEquals(department, employee3.getDepartment());
  }
コード例 #4
0
ファイル: ModelTest.java プロジェクト: ChenArthur/babyfish
  @Test
  public void testModifyDepartment() {
    Department department1 = new Department();
    Department department2 = new Department();
    Employee employee1 = new Employee();
    Employee employee2 = new Employee();
    Utils.assertCollection(department1.getEmployees().keySet());
    Utils.assertCollection(department1.getEmployees().values());
    Utils.assertCollection(department2.getEmployees().keySet());
    Utils.assertCollection(department2.getEmployees().values());
    Assert.assertNull(employee1.getCodeInDepartment());
    Assert.assertNull(employee1.getDepartment());
    Assert.assertNull(employee2.getCodeInDepartment());
    Assert.assertNull(employee2.getDepartment());

    department1.getEmployees().put("I", employee1);
    Utils.assertCollection(department1.getEmployees().keySet(), "I");
    Utils.assertCollection(department1.getEmployees().values(), employee1);
    Utils.assertCollection(department2.getEmployees().keySet());
    Utils.assertCollection(department2.getEmployees().values());
    Assert.assertEquals("I", employee1.getCodeInDepartment());
    Assert.assertEquals(department1, employee1.getDepartment());
    Assert.assertNull(employee2.getCodeInDepartment());
    Assert.assertNull(employee2.getDepartment());

    department1.getEmployees().put("II", employee2);
    Utils.assertCollection(department1.getEmployees().keySet(), "I", "II");
    Utils.assertCollection(department1.getEmployees().values(), employee1, employee2);
    Utils.assertCollection(department2.getEmployees().keySet());
    Utils.assertCollection(department2.getEmployees().values());
    Assert.assertEquals("I", employee1.getCodeInDepartment());
    Assert.assertEquals(department1, employee1.getDepartment());
    Assert.assertEquals("II", employee2.getCodeInDepartment());
    Assert.assertEquals(department1, employee2.getDepartment());

    department2.getEmployees().put("III", employee1);
    Utils.assertCollection(department1.getEmployees().keySet(), "II");
    Utils.assertCollection(department1.getEmployees().values(), employee2);
    Utils.assertCollection(department2.getEmployees().keySet(), "III");
    Utils.assertCollection(department2.getEmployees().values(), employee1);
    Assert.assertEquals("III", employee1.getCodeInDepartment());
    Assert.assertEquals(department2, employee1.getDepartment());
    Assert.assertEquals("II", employee2.getCodeInDepartment());
    Assert.assertEquals(department1, employee2.getDepartment());

    department2.getEmployees().put("IV", employee2);
    Utils.assertCollection(department1.getEmployees().keySet());
    Utils.assertCollection(department1.getEmployees().values());
    Utils.assertCollection(department2.getEmployees().keySet(), "III", "IV");
    Utils.assertCollection(department2.getEmployees().values(), employee1, employee2);
    Assert.assertEquals("III", employee1.getCodeInDepartment());
    Assert.assertEquals(department2, employee1.getDepartment());
    Assert.assertEquals("IV", employee2.getCodeInDepartment());
    Assert.assertEquals(department2, employee2.getDepartment());

    department2.getEmployees().keySet().remove("III");
    Utils.assertCollection(department1.getEmployees().keySet());
    Utils.assertCollection(department1.getEmployees().values());
    Utils.assertCollection(department2.getEmployees().keySet(), "IV");
    Utils.assertCollection(department2.getEmployees().values(), employee2);
    Assert.assertNull(employee1.getCodeInDepartment());
    Assert.assertNull(employee1.getDepartment());
    Assert.assertEquals("IV", employee2.getCodeInDepartment());
    Assert.assertEquals(department2, employee2.getDepartment());

    department2.getEmployees().values().remove(employee2);
    Utils.assertCollection(department1.getEmployees().keySet());
    Utils.assertCollection(department1.getEmployees().values());
    Utils.assertCollection(department2.getEmployees().keySet());
    Utils.assertCollection(department2.getEmployees().values());
    Assert.assertNull(employee1.getCodeInDepartment());
    Assert.assertNull(employee1.getDepartment());
    Assert.assertNull(employee2.getCodeInDepartment());
    Assert.assertNull(employee2.getDepartment());
  }