### Question:
Dijkastra { public static void run(Graph graph, Map<Node, Integer> nodeCostMap, Map<Node, Node> parentNodeMap) { if (graph.start == graph.end) { return; } List<Edge> edges = graph.nodeMap.get(graph.start); Objects.requireNonNull(edges); edges.forEach(edge -> { Integer toNodeWeight = nodeCostMap.get(edge.to); Integer fromNodeWeight = nodeCostMap.getOrDefault(edge.from, 0); Integer nowToWeight = fromNodeWeight + edge.weight; if (toNodeWeight == null || nowToWeight < toNodeWeight) { nodeCostMap.put(edge.to, nowToWeight); parentNodeMap.put(edge.to, edge.from); } graph.start = edge.to; run(graph, nodeCostMap, parentNodeMap); }); }  static void run(Graph graph,
                           Map<Node, Integer> nodeCostMap,
                           Map<Node, Node> parentNodeMap);  }### Answer:
@Test public void run_When_Graph_Only_Has_One_Node() throws Exception { graph = new Graph(nodeMap, end, end); Dijkastra.run(graph, nodeCostMap, parentNodeMap); assertThat(nodeCostMap.keySet(), hasSize(0)); assertThat(nodeCostMap.get(end), nullValue()); }
@Test public void run_When_Graph_Only_Has_Two_Nodes() throws Exception { graph = new Graph(nodeMap, node2, end); Dijkastra.run(graph, nodeCostMap, parentNodeMap); assertThat(nodeCostMap.keySet(), hasSize(1)); assertThat(nodeCostMap.get(end), is(25)); assertThat(parentNodeMap.get(end), is(node2)); }
@Test public void run_When_Graph_Multi() throws Exception { graph = new Graph(nodeMap, node1, end); Dijkastra.run(graph, nodeCostMap, parentNodeMap); assertThat(nodeCostMap.get(end), is(10)); assertThat(methodPrintShortestRoute.invoke(Dijkastra.class, end, parentNodeMap), is("node1->end")); }
@Test public void run_When_Graph_All() throws Exception { graph = new Graph(nodeMap, start, end); Dijkastra.run(graph, nodeCostMap, parentNodeMap); assertThat(nodeCostMap.get(end), is(20)); assertThat(methodPrintShortestRoute.invoke(Dijkastra.class, end, parentNodeMap).toString(), is("start->node1->end")); }