AccessibilityNodeInfoQueueBuilder { public Queue<AccessibilityNodeInfoSorter> buildPriorityQueue(AccessibilityNodeInfo rootNode) { PriorityQueue<AccessibilityNodeInfoSorter> queue = new PriorityQueue<>(); recursivelyEnqueueNodes(queue, rootNode, Long.MAX_VALUE); return queue; } AccessibilityNodeInfoQueueBuilder(AccessibilityNodeInfoSorterFactory nodeSorterFactory); Queue<AccessibilityNodeInfoSorter> buildPriorityQueue(AccessibilityNodeInfo rootNode);  }
@Test public void buildEmptyQueue() { Queue<AccessibilityNodeInfoSorter> queue = testSubject.buildPriorityQueue(null); Assert.assertNotNull(queue); Assert.assertTrue(queue.isEmpty()); }
@Test public void buildSingleNodeQueue() { Queue<AccessibilityNodeInfoSorter> queue = testSubject.buildPriorityQueue(rootNode); Assert.assertNotNull(queue); Assert.assertEquals(queue.size(), 1); verify(nodeSorterFactory).createNodeSorter(rootNode, Long.MAX_VALUE); assertNextQueueItemEquals(queue, rootNode, Long.MAX_VALUE); }
@Test public void buildQueueWithChildren() { createChildren(); Queue<AccessibilityNodeInfoSorter> queue = testSubject.buildPriorityQueue(rootNode); Long rootOrder = Long.MAX_VALUE; Long childOrder = rootOrder - 1; Long grandchildOrder = rootOrder - 2; verifyAllNodesCreated(rootOrder, childOrder, childOrder, grandchildOrder); Assert.assertEquals(queue.size(), 4); assertNextQueueItemEquals(queue, grandchildNode, grandchildOrder); if (queue.peek().node == childNode0) { assertNextQueueItemEquals(queue, childNode0, childOrder); assertNextQueueItemEquals(queue, childNode1, childOrder); } else { assertNextQueueItemEquals(queue, childNode1, childOrder); assertNextQueueItemEquals(queue, childNode0, childOrder); } assertNextQueueItemEquals(queue, rootNode, rootOrder); }
@Test public void buildQueueWithLabelNodes() { createChildren(); when(childNode0.getLabelFor()).thenReturn(childNode1); Queue<AccessibilityNodeInfoSorter> queue = testSubject.buildPriorityQueue(rootNode); Long rootOrder = Long.MAX_VALUE; Long child0Order = (rootOrder - 1) / 2; Long child1Order = rootOrder - 1; Long grandchildOrder = child0Order - 1; verifyAllNodesCreated(rootOrder, child0Order, child1Order, grandchildOrder); Assert.assertEquals(queue.size(), 4); assertNextQueueItemEquals(queue, grandchildNode, grandchildOrder); assertNextQueueItemEquals(queue, childNode0, child0Order); assertNextQueueItemEquals(queue, childNode1, child1Order); assertNextQueueItemEquals(queue, rootNode, rootOrder); }