### Question:
DMNDiagramUtils { public Definitions getDefinitions(final Diagram diagram) { return getDefinitionStream(diagram) .filter(d -> d instanceof DMNDiagram) .map(d -> (DMNDiagram) d) .findFirst() .map(DMNDiagram::getDefinitions) .orElse(NONE); } DMNDiagramUtils(); List<DRGElement> getDRGElements(final Diagram diagram); String getNamespace(final Diagram diagram); Definitions getDefinitions(final Diagram diagram); Stream<Object> getDefinitionStream(final Diagram diagram); @SuppressWarnings("unchecked") Stream<Node> getNodeStream(final Diagram diagram);  }### Answer:
@Test public void testGetDefinitionsWithRootNode() { final DMNDiagram definition = new DMNDiagram(); graph.addNode(newNode(definition)); final Definitions definitions = utils.getDefinitions(diagram); assertNotNull(definitions); assertEquals(definition.getDefinitions(), definitions); }
@Test public void testGetDefinitionsWithMultipleRootNodes() { final Decision definition1 = new Decision(); final DMNDiagram definition2 = new DMNDiagram(); graph.addNode(newNode(definition1)); graph.addNode(newNode(definition2)); final Definitions definitions = utils.getDefinitions(diagram); assertNotNull(definitions); assertEquals(definition2.getDefinitions(), definitions); }
@Test public void testGetDefinitionsWithConnectedNodes() { final Decision definition1 = new Decision(); final DMNDiagram definition2 = new DMNDiagram(); final Node<View, Edge> node1 = newNode(definition1); final Node<View, Edge> node2 = newNode(definition2); final Edge<View, Node> edge = new EdgeImpl<>(UUID.uuid()); node1.getInEdges().add(edge); node2.getOutEdges().add(edge); edge.setSourceNode(node2); edge.setTargetNode(node1); graph.addNode(node1); graph.addNode(node2); final Definitions definitions = utils.getDefinitions(diagram); assertNotNull(definitions); assertEquals(definition2.getDefinitions(), definitions); }
@Test public void testGetDefinitionsWithNoNodes() { assertNull(utils.getDefinitions(diagram)); }