HierarchyTreeNode implements Iterable<HierarchyTreeNode>, Streamable<HierarchyTreeNode>, Serializable { boolean managersEqual(HierarchyTreeNode other) { var otherManager = Objects.requireNonNull(other).manager; if(manager == otherManager) { return true; } else if(Objects.isNull(manager) || Objects.isNull(otherManager)) { return false; } return Objects.equals(manager.id, otherManager.id); } HierarchyTreeNode(User user); boolean isLeaf(); boolean isRoot(); HierarchyTreeNode getRoot(); void addDirectStaffMember(HierarchyTreeNode staffNode); void removeDirectStaffMember(HierarchyTreeNode staffNode); @Override Iterator<HierarchyTreeNode> iterator(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void managersEqualReturnsTrueWhenSameManagerInstance() { var node = new HierarchyTreeNode(userMock); assertThat(node.managersEqual(node)).isTrue(); }
@Test public void managersEqualReturnsTrueWhenSameId() { var managerNodeId = 1L; var managerNode = new HierarchyTreeNode(otherUserMock); var otherManagerNode = new HierarchyTreeNode(); managerNode.id = managerNodeId; otherManagerNode.id = managerNodeId; var node = new HierarchyTreeNode(userMock); node.manager = managerNode; var otherNode = new HierarchyTreeNode(userMock); otherNode.manager = otherManagerNode; assertThat(node.managersEqual(otherNode)).isTrue(); }
@Test public void managersEqualReturnsTrueWhenBothManagersNull() { var node = new HierarchyTreeNode(userMock); var otherNode = new HierarchyTreeNode(otherUserMock); assertThat(node.managersEqual(otherNode)).isTrue(); }
@Test public void managersEqualReturnsFalseWhenOneNull() { var node = new HierarchyTreeNode(userMock); var otherNode = new HierarchyTreeNode(otherUserMock); otherNode.manager = node; assertThat(node.managersEqual(otherNode)).isFalse(); }
@Test public void managersEqualReturnsFalseWhenDifferentManagerId() { var managerNodeId = 1L; var otherManagerNodeId = 2L; var managerNode = new HierarchyTreeNode(otherUserMock); var otherManagerNode = new HierarchyTreeNode(); managerNode.id = managerNodeId; otherManagerNode.id = otherManagerNodeId; var node = new HierarchyTreeNode(userMock); node.manager = managerNode; var otherNode = new HierarchyTreeNode(userMock); otherManagerNode.manager = otherManagerNode; assertThat(node.managersEqual(otherNode)).isFalse(); }