@Test public void getBuildChainOnComplexTreeShouldWork() { Commit a = new Commit("A"); Commit b = new Commit("B", a); Commit c = new Commit("C", a); Commit d = new Commit("D", b); Commit e = new Commit("E", b); Commit f = new Commit("F", c); Commit g = new Commit("G", e); DependencyGraph<Commit> testee = new DependencyGraph<>(Commit::getParent); Stream.of(b, a, e, g, d, f, c) .forEach(testee::registerItem); Stream<Commit> actual = testee.getBuildChain(); assertThat(actual).extracting(Commit::getMessage).containsExactly("A", "B", "C", "E", "D", "F", "G"); }
public Stream<T> getBuildChain() throws CycleDetectedException { DefaultDirectedGraph<T, DefaultEdge> graph = builder.build(); ensureNoCycle(graph); return Iterators.toStream(new TopologicalOrderIterator<>(graph)); }
DependencyGraph { public Stream<T> getBuildChain() throws CycleDetectedException { DefaultDirectedGraph<T, DefaultEdge> graph = builder.build(); ensureNoCycle(graph); return Iterators.toStream(new TopologicalOrderIterator<>(graph)); } }
DependencyGraph { public Stream<T> getBuildChain() throws CycleDetectedException { DefaultDirectedGraph<T, DefaultEdge> graph = builder.build(); ensureNoCycle(graph); return Iterators.toStream(new TopologicalOrderIterator<>(graph)); } DependencyGraph(Function<T, Optional<T>> getParent); }
DependencyGraph { public Stream<T> getBuildChain() throws CycleDetectedException { DefaultDirectedGraph<T, DefaultEdge> graph = builder.build(); ensureNoCycle(graph); return Iterators.toStream(new TopologicalOrderIterator<>(graph)); } DependencyGraph(Function<T, Optional<T>> getParent); void registerItem(T item); Stream<T> getBuildChain(); String toString(); }
DependencyGraph { public Stream<T> getBuildChain() throws CycleDetectedException { DefaultDirectedGraph<T, DefaultEdge> graph = builder.build(); ensureNoCycle(graph); return Iterators.toStream(new TopologicalOrderIterator<>(graph)); } DependencyGraph(Function<T, Optional<T>> getParent); void registerItem(T item); Stream<T> getBuildChain(); String toString();  }