@Test public void testMergeOrAddNodeToDefinitions() { final JSITDecision existingNode1 = makeDecision("id1"); final JSITDecision node1 = makeDecision("id1"); final JSITBusinessKnowledgeModel node2 = makeBusinessKnowledgeModel("id2"); final JSITKnowledgeSource node3 = makeKnowledgeSource("id3"); final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller()); final JSITDefinitions definitions = spy(new JSITDefinitions()); final List<JSITDRGElement> definitionsDRGElements = new ArrayList<>(singletonList(existingNode1)); doReturn(node1).when(dmnMarshaller).getWrappedJSITDRGElement(eq(node1), any()); doReturn(node2).when(dmnMarshaller).getWrappedJSITDRGElement(eq(node2), any()); doReturn(node3).when(dmnMarshaller).getWrappedJSITDRGElement(eq(node3), any()); doReturn(true).when(dmnMarshaller).instanceOfDecision(eq(node1)); doReturn(true).when(dmnMarshaller).instanceOfBusinessKnowledgeModel(eq(node2)); doReturn(true).when(dmnMarshaller).instanceOfKnowledgeSource(eq(node3)); doReturn(definitionsDRGElements).when(definitions).getDrgElement(); final List<JSITAuthorityRequirement> authorityRequirement = new ArrayList<>(singletonList(new JSITAuthorityRequirement())); final List<JSITInformationRequirement> informationRequirement = new ArrayList<>(singletonList(new JSITInformationRequirement())); final List<JSITKnowledgeRequirement> knowledgeRequirement = new ArrayList<>(singletonList(new JSITKnowledgeRequirement())); doReturn(authorityRequirement).when(node1).getAuthorityRequirement(); doReturn(informationRequirement).when(node1).getInformationRequirement(); doReturn(knowledgeRequirement).when(node1).getKnowledgeRequirement(); dmnMarshaller.mergeOrAddNodeToDefinitions(node1, definitions); dmnMarshaller.mergeOrAddNodeToDefinitions(node2, definitions); dmnMarshaller.mergeOrAddNodeToDefinitions(node3, definitions); verify(definitions, never()).addDrgElement(node1); verify(definitions).addDrgElement(node2); verify(definitions).addDrgElement(node3); verify(existingNode1).addAllAuthorityRequirement(authorityRequirement.toArray(new JSITAuthorityRequirement[0])); verify(existingNode1).addAllInformationRequirement(informationRequirement.toArray(new JSITInformationRequirement[0])); verify(existingNode1).addAllKnowledgeRequirement(knowledgeRequirement.toArray(new JSITKnowledgeRequirement[0])); }
void mergeOrAddNodeToDefinitions(final JSITDRGElement node, final JSITDefinitions definitions) { final Optional<JSITDRGElement> existingNode = getExistingNode(definitions, node); if (existingNode.isPresent()) { final JSITDRGElement existingDRGElement = Js.uncheckedCast(existingNode.get()); mergeNodeRequirements(node, existingDRGElement); } else { addNodeToDefinitions(node, definitions); } }
DMNMarshaller { void mergeOrAddNodeToDefinitions(final JSITDRGElement node, final JSITDefinitions definitions) { final Optional<JSITDRGElement> existingNode = getExistingNode(definitions, node); if (existingNode.isPresent()) { final JSITDRGElement existingDRGElement = Js.uncheckedCast(existingNode.get()); mergeNodeRequirements(node, existingDRGElement); } else { addNodeToDefinitions(node, definitions); } } }
DMNMarshaller { void mergeOrAddNodeToDefinitions(final JSITDRGElement node, final JSITDefinitions definitions) { final Optional<JSITDRGElement> existingNode = getExistingNode(definitions, node); if (existingNode.isPresent()) { final JSITDRGElement existingDRGElement = Js.uncheckedCast(existingNode.get()); mergeNodeRequirements(node, existingDRGElement); } else { addNodeToDefinitions(node, definitions); } } protected  DMNMarshaller(); @Inject  DMNMarshaller(final FactoryManager factoryManager); }
DMNMarshaller { void mergeOrAddNodeToDefinitions(final JSITDRGElement node, final JSITDefinitions definitions) { final Optional<JSITDRGElement> existingNode = getExistingNode(definitions, node); if (existingNode.isPresent()) { final JSITDRGElement existingDRGElement = Js.uncheckedCast(existingNode.get()); mergeNodeRequirements(node, existingDRGElement); } else { addNodeToDefinitions(node, definitions); } } protected  DMNMarshaller(); @Inject  DMNMarshaller(final FactoryManager factoryManager); @PostConstruct void init(); JSITDefinitions marshall(); List<Node> getNodeStream(final Diagram diagram); @SuppressWarnings("unchecked") JSITDRGElement stunnerToDMN(final Node<?, ?> node,
                                       final Consumer<JSITComponentWidths> componentWidthsConsumer); }
DMNMarshaller { void mergeOrAddNodeToDefinitions(final JSITDRGElement node, final JSITDefinitions definitions) { final Optional<JSITDRGElement> existingNode = getExistingNode(definitions, node); if (existingNode.isPresent()) { final JSITDRGElement existingDRGElement = Js.uncheckedCast(existingNode.get()); mergeNodeRequirements(node, existingDRGElement); } else { addNodeToDefinitions(node, definitions); } } protected  DMNMarshaller(); @Inject  DMNMarshaller(final FactoryManager factoryManager); @PostConstruct void init(); JSITDefinitions marshall(); List<Node> getNodeStream(final Diagram diagram); @SuppressWarnings("unchecked") JSITDRGElement stunnerToDMN(final Node<?, ?> node,
                                       final Consumer<JSITComponentWidths> componentWidthsConsumer); static final String PREFIX; }