@Test public final void shouldReturnListOfNodesInTheSameOrderAsTheyAppearOnTheTree() throws Exception { EntityTreeNode l1b1a11 = mockEntityTreeNode(null, 1, "1.B.1.A.11"); EntityTreeNode l1b1a10 = mockEntityTreeNode(Lists.newArrayList(l1b1a11), 1, "1.B.1.A.10"); EntityTreeNode l1b1a9 = mockEntityTreeNode(Lists.newArrayList(l1b1a10), 1, "1.B.1.A.9"); EntityTreeNode l1b1a8 = mockEntityTreeNode(Lists.newArrayList(l1b1a9), 1, "1.B.1.A.8"); EntityTreeNode l1b1a7 = mockEntityTreeNode(Lists.newArrayList(l1b1a8), 1, "1.B.1.A.7"); EntityTreeNode l1b1a6 = mockEntityTreeNode(Lists.newArrayList(l1b1a7), 1, "1.B.1.A.6"); EntityTreeNode l1b1a5 = mockEntityTreeNode(Lists.newArrayList(l1b1a6), 1, "1.B.1.A.5"); EntityTreeNode l1b1a4 = mockEntityTreeNode(Lists.newArrayList(l1b1a5), 1, "1.B.1.A.4"); EntityTreeNode l1b1a3 = mockEntityTreeNode(Lists.newArrayList(l1b1a4), 1, "1.B.1.A.3"); EntityTreeNode l1b1a2 = mockEntityTreeNode(Lists.newArrayList(l1b1a3), 1, "1.B.1.A.2"); EntityTreeNode l1b1a1 = mockEntityTreeNode(Lists.newArrayList(l1b1a2), 1, "1.B.1.A.1"); EntityTreeNode l1b1b1 = mockEntityTreeNode(null, 2, "1.B.1.B.1"); EntityTreeNode l1a1 = mockEntityTreeNode(null, 1, "1.A.1"); EntityTreeNode l1b1 = mockEntityTreeNode(Lists.newLinkedList(Lists.newArrayList(l1b1b1, l1b1a1)), 2, "1.B.1"); EntityTreeNode root = mockEntityTreeNode(Lists.newLinkedList(Lists.newArrayList(l1a1, l1b1)), 1, "1"); given(tree.getRoot()).willReturn(root); given(tree.isEmpty()).willReturn(false); List<Entity> nodesList = entityTreeUtils.getSortedEntities(tree); Assert.assertEquals(15, nodesList.size()); Assert.assertEquals("1", nodesList.get(0).getField("nodeNumber")); Assert.assertEquals("1.A.1", nodesList.get(1).getField("nodeNumber")); Assert.assertEquals("1.B.1", nodesList.get(2).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.1", nodesList.get(3).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.2", nodesList.get(4).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.3", nodesList.get(5).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.4", nodesList.get(6).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.5", nodesList.get(7).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.6", nodesList.get(8).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.7", nodesList.get(9).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.8", nodesList.get(10).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.9", nodesList.get(11).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.10", nodesList.get(12).getField("nodeNumber")); Assert.assertEquals("1.B.1.A.11", nodesList.get(13).getField("nodeNumber")); Assert.assertEquals("1.B.1.B.1", nodesList.get(14).getField("nodeNumber")); }
public List<Entity> getSortedEntities(final EntityTree tree) { List<Entity> nodesList = Lists.newLinkedList(); if (tree.isEmpty()) { return nodesList; } return getSortedEntitiesFromNode(tree.getRoot()); }
EntityTreeUtilsService { public List<Entity> getSortedEntities(final EntityTree tree) { List<Entity> nodesList = Lists.newLinkedList(); if (tree.isEmpty()) { return nodesList; } return getSortedEntitiesFromNode(tree.getRoot()); } }
EntityTreeUtilsService { public List<Entity> getSortedEntities(final EntityTree tree) { List<Entity> nodesList = Lists.newLinkedList(); if (tree.isEmpty()) { return nodesList; } return getSortedEntitiesFromNode(tree.getRoot()); }  }
EntityTreeUtilsService { public List<Entity> getSortedEntities(final EntityTree tree) { List<Entity> nodesList = Lists.newLinkedList(); if (tree.isEmpty()) { return nodesList; } return getSortedEntitiesFromNode(tree.getRoot()); }  static EntityTree getDetachedEntityTree(final List<Entity> entities); List<Entity> getSortedEntities(final EntityTree tree); }
EntityTreeUtilsService { public List<Entity> getSortedEntities(final EntityTree tree) { List<Entity> nodesList = Lists.newLinkedList(); if (tree.isEmpty()) { return nodesList; } return getSortedEntitiesFromNode(tree.getRoot()); }  static EntityTree getDetachedEntityTree(final List<Entity> entities); List<Entity> getSortedEntities(final EntityTree tree);  }