EventUtil { public static void inspectHierarchy(Element node, Collection<Element> descendants, Predicate<Element> filter) { node.accept(new DescendantsVisitor(descendants, filter)); } private  EventUtil(); static List<BeforeEnterObserver> collectBeforeEnterObservers(
            Collection<? extends HasElement> oldChain,
            Collection<? extends HasElement> newChain); static List<BeforeEnterObserver> collectBeforeEnterObserversFromChain(
            Collection<? extends HasElement> chain,
            Collection<? extends HasElement> childrenExclusions); static List<BeforeEnterObserver> collectBeforeEnterObserversFromChainElement(
            HasElement element,
            Collection<? extends HasElement> childrenExclusions); static List<BeforeLeaveObserver> collectBeforeLeaveObservers(UI ui); static List<AfterNavigationObserver> collectAfterNavigationObservers(
            UI ui); static List<LocaleChangeObserver> collectLocaleChangeObservers(
            Element element); static List<LocaleChangeObserver> collectLocaleChangeObservers(
            List<HasElement> components); static void informLocaleChangeObservers(UI ui); static void informLocaleChangeObservers(UI ui,
            List<HasElement> components); static Stream<T> getImplementingComponents(
            Stream<Element> elementStream, Class<T> type); static void inspectHierarchy(Element node,
            Collection<Element> descendants, Predicate<Element> filter);  }
@Test public void inspectChildrenHierarchy() throws Exception { Element node = new Element("root"); node.appendChild(new Element("main"), new Element("menu")); Element nested = new Element("nested"); nested.appendChild(new Element("nested-child"), new Element("nested-child-2")); node.appendChild(nested); List<Element> elements = new ArrayList<>(); EventUtil.inspectHierarchy(node, elements, element -> true); Assert.assertEquals("Missing elements from list.", 6, elements.size()); }
@Test public void inspectChildrenHierarchy_selective() throws Exception { Element node = new Element("root"); node.appendChild(new Element("main"), new Element("menu")); Element nested = new Element("nested"); nested.appendChild(new Element("nested-child"), new Element("nested-child-2")); node.appendChild(nested); List<Element> elements = new ArrayList<>(); EventUtil.inspectHierarchy(node, elements, element -> !nested.equals(element)); Assert.assertEquals("Missing elements from list.", 3, elements.size()); }
@Test public void inspectMixedChildrenHierarchy() throws Exception { Element node = new Element("root"); node.appendVirtualChild(new Element("main"), new Element("menu")); Element nested = new Element("nested"); nested.appendVirtualChild(new Element("nested-virtual-child"), new Element("nested-virtual-child-2")); nested.appendChild(new Element("nested-child"), new Element("nested-child-2")); nested.getStateProvider().appendVirtualChild(nested.getNode(), new Element("attached-by-id"), NodeProperties.INJECT_BY_ID, "id"); nested.getStateProvider().appendVirtualChild(nested.getNode(), new Element("attached-by-id"), NodeProperties.TEMPLATE_IN_TEMPLATE, ""); node.appendChild(nested); List<Element> elements = new ArrayList<>(); EventUtil.inspectHierarchy(node, elements, element -> true); Assert.assertEquals("Missing elements from list.", 10, elements.size()); }