@Test public void testDeleteGlobalGraphNodes() { final Node node = mock(Node.class); final GraphsProvider graphsProvider = mock(GraphsProvider.class); final Deque nodes = new ArrayDeque(); final TreeWalkTraverseProcessor treeWalk = mock(TreeWalkTraverseProcessor.class); final List<Graph> graphs = Arrays.asList(graphHolder.graph, graphHolderContainer.graph, graphHolderDocked.graph); when(graphsProvider.isGlobalGraphSelected()).thenReturn(false); this.tested = spy(new SafeDeleteNodeProcessor(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()), graphHolder.graph, node, true, treeWalk, graphsProvider)); when(graphsProvider.getGraphs()).thenReturn(graphs); doReturn(nodes).when(tested).createNodesDequeue(); doReturn(true).when(tested).processGlobalNodeForDeletion(any(Node.class), eq(nodes)); tested.deleteGlobalGraphNodes(callback, nodes); verify(treeWalk).traverse(eq(graphHolder.graph), any(AbstractTreeTraverseCallback.class)); verify(treeWalk).traverse(eq(graphHolderContainer.graph), any(AbstractTreeTraverseCallback.class)); verify(treeWalk).traverse(eq(graphHolderDocked.graph), any(AbstractTreeTraverseCallback.class)); }
protected void deleteGlobalGraphNodes(final Callback callback, final Deque<Node<View, Edge>> nodes) { treeWalkTraverseProcessor.ifPresent(treeWalk -> { graphsProvider.get().getGraphs().stream().forEach(existingGraph -> { treeWalk.traverse(existingGraph, new AbstractTreeTraverseCallback<Graph, Node, Edge>() { @Override public boolean startNodeTraversal(final Node node) { super.startNodeTraversal(node); return processGlobalNodeForDeletion(node, nodes); } @Override public boolean startEdgeTraversal(final Edge edge) { super.startEdgeTraversal(edge); return true; } }); }); }); nodes.descendingIterator().forEachRemaining(node -> processNode(node, callback, false)); }
SafeDeleteNodeProcessor { protected void deleteGlobalGraphNodes(final Callback callback, final Deque<Node<View, Edge>> nodes) { treeWalkTraverseProcessor.ifPresent(treeWalk -> { graphsProvider.get().getGraphs().stream().forEach(existingGraph -> { treeWalk.traverse(existingGraph, new AbstractTreeTraverseCallback<Graph, Node, Edge>() { @Override public boolean startNodeTraversal(final Node node) { super.startNodeTraversal(node); return processGlobalNodeForDeletion(node, nodes); } @Override public boolean startEdgeTraversal(final Edge edge) { super.startEdgeTraversal(edge); return true; } }); }); }); nodes.descendingIterator().forEachRemaining(node -> processNode(node, callback, false)); } }
SafeDeleteNodeProcessor { protected void deleteGlobalGraphNodes(final Callback callback, final Deque<Node<View, Edge>> nodes) { treeWalkTraverseProcessor.ifPresent(treeWalk -> { graphsProvider.get().getGraphs().stream().forEach(existingGraph -> { treeWalk.traverse(existingGraph, new AbstractTreeTraverseCallback<Graph, Node, Edge>() { @Override public boolean startNodeTraversal(final Node node) { super.startNodeTraversal(node); return processGlobalNodeForDeletion(node, nodes); } @Override public boolean startEdgeTraversal(final Edge edge) { super.startEdgeTraversal(edge); return true; } }); }); }); nodes.descendingIterator().forEachRemaining(node -> processNode(node, callback, false)); } SafeDeleteNodeProcessor(final ChildrenTraverseProcessor childrenTraverseProcessor,
                                   final Graph graph,
                                   final Node<Definition<?>, Edge> candidate);  SafeDeleteNodeProcessor(final ChildrenTraverseProcessor childrenTraverseProcessor,
                                   final Graph graph,
                                   final Node<Definition<?>, Edge> candidate,
                                   final boolean keepChildren,
                                   final TreeWalkTraverseProcessor treeWalkTraverseProcessor,
                                   final GraphsProvider graphsProvider); }
SafeDeleteNodeProcessor { protected void deleteGlobalGraphNodes(final Callback callback, final Deque<Node<View, Edge>> nodes) { treeWalkTraverseProcessor.ifPresent(treeWalk -> { graphsProvider.get().getGraphs().stream().forEach(existingGraph -> { treeWalk.traverse(existingGraph, new AbstractTreeTraverseCallback<Graph, Node, Edge>() { @Override public boolean startNodeTraversal(final Node node) { super.startNodeTraversal(node); return processGlobalNodeForDeletion(node, nodes); } @Override public boolean startEdgeTraversal(final Edge edge) { super.startEdgeTraversal(edge); return true; } }); }); }); nodes.descendingIterator().forEachRemaining(node -> processNode(node, callback, false)); } SafeDeleteNodeProcessor(final ChildrenTraverseProcessor childrenTraverseProcessor,
                                   final Graph graph,
                                   final Node<Definition<?>, Edge> candidate);  SafeDeleteNodeProcessor(final ChildrenTraverseProcessor childrenTraverseProcessor,
                                   final Graph graph,
                                   final Node<Definition<?>, Edge> candidate,
                                   final boolean keepChildren,
                                   final TreeWalkTraverseProcessor treeWalkTraverseProcessor,
                                   final GraphsProvider graphsProvider); @SuppressWarnings("unchecked") void run(final Callback callback); String getCandidateDiagramId(); String getCandidateContentDefinitionId(); }
SafeDeleteNodeProcessor { protected void deleteGlobalGraphNodes(final Callback callback, final Deque<Node<View, Edge>> nodes) { treeWalkTraverseProcessor.ifPresent(treeWalk -> { graphsProvider.get().getGraphs().stream().forEach(existingGraph -> { treeWalk.traverse(existingGraph, new AbstractTreeTraverseCallback<Graph, Node, Edge>() { @Override public boolean startNodeTraversal(final Node node) { super.startNodeTraversal(node); return processGlobalNodeForDeletion(node, nodes); } @Override public boolean startEdgeTraversal(final Edge edge) { super.startEdgeTraversal(edge); return true; } }); }); }); nodes.descendingIterator().forEachRemaining(node -> processNode(node, callback, false)); } SafeDeleteNodeProcessor(final ChildrenTraverseProcessor childrenTraverseProcessor,
                                   final Graph graph,
                                   final Node<Definition<?>, Edge> candidate);  SafeDeleteNodeProcessor(final ChildrenTraverseProcessor childrenTraverseProcessor,
                                   final Graph graph,
                                   final Node<Definition<?>, Edge> candidate,
                                   final boolean keepChildren,
                                   final TreeWalkTraverseProcessor treeWalkTraverseProcessor,
                                   final GraphsProvider graphsProvider); @SuppressWarnings("unchecked") void run(final Callback callback); String getCandidateDiagramId(); String getCandidateContentDefinitionId();  }