### Question:
ElementHierarchyTraverser { public void traverse(SessionContext context, ElementContext elementContext, Space space, CoreElement element, ElementVisitor visitor) { visitor.visit(context, elementContext, space, element); element.getSubElements().forEach(subElement -> traverse(context, elementContext, space, subElement, visitor) ); } private  ElementHierarchyTraverser(); static ElementHierarchyTraverser init(); void traverse(SessionContext context, ElementContext elementContext,
                       Space space, CoreElement element, ElementVisitor visitor);  }### Answer:
@Test public void testTraverseNoSubs() throws Exception { CoreElement element = new CoreElement(); SessionContext context = TestUtils.createSessionContext(USER, "test"); ElementContext elementContext = new ElementContext(new Id(), new Id()); Space space = Space.PRIVATE; traverser.traverse(context, elementContext, space, element, visitorMock); verify(visitorMock) .visit(context, elementContext, space, element); }
@Test public void testTraverseHirarchy() throws Exception { CoreElement d1211 = createCoreElement(null, Action.CREATE, "d1211"); CoreElement c121 = createCoreElement(new Id(), Action.UPDATE, "c121", d1211); CoreElement b11 = createCoreElement(new Id(), Action.DELETE, "b11"); CoreElement b12 = createCoreElement(new Id(), Action.IGNORE, "b12", c121); CoreElement b21 = createCoreElement(null, Action.CREATE, "b21"); CoreElement b22 = createCoreElement(null, Action.CREATE, "b22"); CoreElement a1 = createCoreElement(new Id(), Action.UPDATE, "a1", b11, b12); CoreElement a2 = createCoreElement(null, Action.CREATE, "a2", b21, b22); CoreElement root = createCoreElement(new Id(), Action.IGNORE, "root", a1, a2); SessionContext context = TestUtils.createSessionContext(USER, "test"); ElementContext elementContext = new ElementContext(new Id(), new Id()); Space space = Space.PRIVATE; traverser.traverse(context, elementContext, space, root, visitorMock); verify(visitorMock).visit(context, elementContext, space, root); verify(visitorMock).visit(context, elementContext, space, a1); verify(visitorMock).visit(context, elementContext, space, a2); verify(visitorMock).visit(context, elementContext, space, b11); verify(visitorMock).visit(context, elementContext, space, b12); verify(visitorMock).visit(context, elementContext, space, b21); verify(visitorMock).visit(context, elementContext, space, b22); verify(visitorMock).visit(context, elementContext, space, c121); verify(visitorMock).visit(context, elementContext, space, d1211); }