ChainBuilder { @SuppressWarnings("unchecked") public Chain<T> orderNodes() { List<T> chain = new ArrayList<>(); OrderedReadyNodes readyNodes = getReadyNodes(); while (!readyNodes.isEmpty() || popAllPhase(readyNodes) ) { Node candidate = readyNodes.pop(); candidate.removed(readyNodes); if ( candidate instanceof ComponentNode) chain.add(((ComponentNode<T>)candidate).getComponent()); } if ( chain.size() != numComponents) throw new CycleDependenciesException(nameProviders); nameProviders = null; return new Chain<>(id, chain); } ChainBuilder(ComponentId id); PhaseNameProvider addPhase(Phase phase); void addComponent(ChainedComponent component); @SuppressWarnings("unchecked") Chain<T> orderNodes();  }
@Test public void testRegular() throws Exception { ChainBuilder chainBuilder = createDependencyHandler(); addAtoG(chainBuilder); Chain<ChainedComponent> res = chainBuilder.orderNodes(); Iterator<ChainedComponent> i = res.components().iterator(); for (char j=0; j< 'G' - 'A'; ++j) { assertEquals(String.valueOf((char)('A' + j)), name(i.next())); } }