### Question:
AssociationConverter { public Result<BasePropertyWriter> toFlowElement(Edge<?, ?> edge, ElementContainer process) { ViewConnector<Association> connector = (ViewConnector<Association>) edge.getContent(); Association definition = connector.getDefinition(); org.eclipse.bpmn2.Association association = bpmn2.createAssociation(); AssociationPropertyWriter p = propertyWriterFactory.of(association); association.setId(edge.getUUID()); BasePropertyWriter pSrc = process.getChildElement(edge.getSourceNode().getUUID()); BasePropertyWriter pTgt = process.getChildElement(edge.getTargetNode().getUUID()); if (pSrc == null || pTgt == null) { String msg = "BasePropertyWriter was not found for source node or target node at edge: " + edge.getUUID() + ", pSrc = " + pSrc + ", pTgt = " + pTgt; return Result.failure(msg); } p.setSource(pSrc); p.setTarget(pTgt); p.setConnection(connector); BPMNGeneralSet general = definition.getGeneral(); p.setDocumentation(general.getDocumentation().getValue()); p.setDirectionAssociation(definition); return Result.of(p); } AssociationConverter(PropertyWriterFactory propertyWriterFactory); Result<BasePropertyWriter> toFlowElement(Edge<?, ?> edge, ElementContainer process);  }### Answer:
@Test public void testToFlowElementSuccess() { org.kie.workbench.common.stunner.bpmn.definition.Association association = new org.kie.workbench.common.stunner.bpmn.definition.DirectionalAssociation(); association.setGeneral(new BPMNGeneralSet("nameValue", "documentationValue")); when(connector.getDefinition()).thenReturn(association); Result<BasePropertyWriter> result = converter.toFlowElement(edge, process); assertTrue(result.isSuccess()); verify(propertyWriterFactory).of(argumentCaptor.capture()); assertEquals(EDGE_ID, argumentCaptor.getValue().getId()); verify(associationPropertyWriter).setSource(pSrc); verify(associationPropertyWriter).setTarget(pTgt); verify(associationPropertyWriter).setConnection(connector); verify(associationPropertyWriter).setDocumentation("documentationValue"); verify(associationPropertyWriter).setDirectionAssociation(association); }
@Test public void testToFlowElementWithSourceMissingFailure() { when(process.getChildElement(SOURCE_NODE_ID)).thenReturn(null); Result<BasePropertyWriter> result = converter.toFlowElement(edge, process); verifyFailure(String.format(ERROR_PATTERN, EDGE_ID, null, pTgt), result); }
@Test public void testToFlowElementWithTargetMissingFailure() { when(process.getChildElement(TARGET_NODE_ID)).thenReturn(null); Result<BasePropertyWriter> result = converter.toFlowElement(edge, process); verifyFailure(String.format(ERROR_PATTERN, EDGE_ID, pSrc, null), result); }
@Test public void testToFlowElementWithSourceAndTargetMissingFailure() { when(process.getChildElement(SOURCE_NODE_ID)).thenReturn(null); when(process.getChildElement(TARGET_NODE_ID)).thenReturn(null); Result<BasePropertyWriter> result = converter.toFlowElement(edge, process); verifyFailure(String.format(ERROR_PATTERN, EDGE_ID, null, null), result); }