HierarchyTreeNode implements Iterable<HierarchyTreeNode>, Streamable<HierarchyTreeNode>, Serializable { public void addDirectStaffMember(HierarchyTreeNode staffNode) { Objects.requireNonNull(staffNode); if(!staffNode.isRoot()) { staffNode.manager.removeDirectStaffMember(staffNode); } directStaff.add(staffNode); staffNode.manager = this; updateIsManagingUser(); addStaffMember(staffNode); } 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 addDirectStaffMemberAddsNodeToItselfAndAllParents() { var rootNode = new HierarchyTreeNode(userMock); rootNode.managingUser = true; var managerNode = new HierarchyTreeNode(otherUserMock); managerNode.manager = rootNode; rootNode.staff.add(managerNode); rootNode.directStaff.add(managerNode); var nodeToAdd = new HierarchyTreeNode(userMock); managerNode.addDirectStaffMember(nodeToAdd); var softly = new SoftAssertions(); softly.assertThat(rootNode.staff).containsExactlyInAnyOrder(managerNode, nodeToAdd); softly.assertThat(rootNode.directStaff).containsExactlyInAnyOrder(managerNode); softly.assertThat(rootNode.managingUser).isTrue(); softly.assertThat(managerNode.manager).isSameAs(rootNode); softly.assertThat(managerNode.staff).containsExactlyInAnyOrder(nodeToAdd); softly.assertThat(managerNode.directStaff).containsExactlyInAnyOrder(nodeToAdd); softly.assertThat(managerNode.managingUser).isTrue(); softly.assertThat(nodeToAdd.manager).isSameAs(managerNode); softly.assertThat(nodeToAdd.staff).isEmpty(); softly.assertThat(nodeToAdd.directStaff).isEmpty(); softly.assertThat(nodeToAdd.managingUser).isFalse(); softly.assertAll(); }