### Question:
DAG { public List<Node> topologicalSort() throws Exception { lock.readLock().lock(); try{ Map.Entry<Boolean, List<Node>> entry = topologicalSortImpl(); if (entry.getKey()) { return entry.getValue(); } throw new Exception("serious error: graph has cycle ! "); }finally { lock.readLock().unlock(); } } DAG(); void addNode(Node node, NodeInfo nodeInfo); boolean addEdge(Node fromNode, Node toNode); boolean addEdge(Node fromNode, Node toNode, EdgeInfo edge, boolean createNode); boolean containsNode(Node node); boolean containsEdge(Node fromNode, Node toNode); NodeInfo getNode(Node node); int getNodesCount(); int getEdgesCount(); Collection<Node> getBeginNode(); Collection<Node> getEndNode(); Set<Node> getPreviousNodes(Node node); Set<Node> getSubsequentNodes(Node node); int getIndegree(Node node); boolean hasCycle(); List<Node> topologicalSort();  }### Answer:
@Test public void testTopologicalSort(){ makeGraph(); try { List<Integer> topoList = new ArrayList<>(); topoList.add(1); topoList.add(3); topoList.add(4); topoList.add(2); topoList.add(5); topoList.add(6); topoList.add(7); assertEquals(graph.topologicalSort(),topoList); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void testTopologicalSort4() { clear(); try { graph.topologicalSort(); } catch (Exception e) { assertTrue(e.getMessage().contains("serious error: graph has cycle")); } }