DAGHelper { public static String cleanDAG(String dag) { ElementsDefinition elementsDefinition = GSON.fromJson(dag, ElementsDefinition.class); Set<String> nodeIDs = elementsDefinition.nodes.stream().map(nodeDefinition -> nodeDefinition.data.id).collect(Collectors.toSet()); elementsDefinition.edges = elementsDefinition.edges.stream().filter(edgeDefinition -> nodeIDs.contains(edgeDefinition.data.source)) .collect(Collectors.toList()); return GSON.toJson(elementsDefinition); } private  DAGHelper(); static String cleanDAG(String dag);  }
@Test public void cleanDAGTest() { String uncleanDAG = fixture("fixtures/uncleanDAG.json"); String cleanDAG = DAGHelper.cleanDAG(uncleanDAG); Assert.assertEquals(fixture("fixtures/cleanDAG.json").replace(" ", "").replace("\n", ""), cleanDAG.trim()); String cleanerDAG = DAGHelper.cleanDAG(cleanDAG); Assert.assertEquals(fixture("fixtures/cleanDAG.json").replace(" ", "").replace("\n", ""), cleanerDAG.trim()); }