### Question:
ElementFactory { public Edge createEdge(FactRecord factRecord, UUID sourceId) { if (factRecord == null || factRecord.getSourceObject() == null || factRecord.getDestinationObject() == null) { return null; } boolean shouldFlip = shouldFlipSourceAndDestination(factRecord, sourceId); UUID inVertexId = shouldFlip ? factRecord.getDestinationObject().getId() : factRecord.getSourceObject().getId(); UUID outVertexId = shouldFlip ? factRecord.getSourceObject().getId() : factRecord.getDestinationObject().getId(); return createAndCache(factRecord, inVertexId, outVertexId); } private  ElementFactory(ActGraph owner); Edge getEdge(UUID id); Edge createEdge(FactRecord factRecord, UUID sourceId); Vertex getVertex(UUID id); static Builder builder();  }### Answer:
@Test public void testCreateEdge() { FactTypeStruct factTypeMock = mockFactType(); ObjectTypeStruct objectTypeMock = mockObjectType(); ObjectRecord source = mockObject(objectTypeMock); ObjectRecord destination = mockObject(objectTypeMock); Edge edge = elementFactory.createEdge(new FactRecord() .setId(UUID.randomUUID()) .setTypeID(factTypeMock.getId()) .setBidirectionalBinding(false) .setSourceObject(source) .setDestinationObject(destination), source.getId()); assertEquals(source.getId(), edge.inVertex().id()); assertEquals(destination.getId(), edge.outVertex().id()); }
@Test public void testCreateBidirectionalEdge() { FactTypeStruct factTypeMock = mockFactType(); ObjectTypeStruct objectTypeMock = mockObjectType(); ObjectRecord source = mockObject(objectTypeMock); ObjectRecord destination = mockObject(objectTypeMock); Edge edge = elementFactory.createEdge(new FactRecord() .setId(UUID.randomUUID()) .setTypeID(factTypeMock.getId()) .setBidirectionalBinding(true) .setDestinationObject(source) .setSourceObject(destination), source.getId()); assertEquals(source.getId(), edge.inVertex().id()); assertEquals(destination.getId(), edge.outVertex().id()); }
@Test public void testCreateBidirectionalEdgeFlipping() { FactTypeStruct factTypeMock = mockFactType(); ObjectTypeStruct objectTypeMock = mockObjectType(); ObjectRecord source = mockObject(objectTypeMock); ObjectRecord destination = mockObject(objectTypeMock); Edge edge = elementFactory.createEdge(new FactRecord() .setId(UUID.randomUUID()) .setTypeID(factTypeMock.getId()) .setBidirectionalBinding(true) .setDestinationObject(source) .setSourceObject(destination), destination.getId()); assertEquals(source.getId(), edge.outVertex().id()); assertEquals(destination.getId(), edge.inVertex().id()); }
@Test public void testCreateEdgesExecutedTwice() { UUID edgeID = UUID.randomUUID(); FactTypeStruct factTypeMock = mockFactType(); ObjectTypeStruct objectTypeMock = mockObjectType(); ObjectRecord objectSource = mockObject(objectTypeMock); ObjectRecord objectDestination = mockObject(objectTypeMock); Edge first = elementFactory.createEdge(new FactRecord() .setId(edgeID) .setTypeID(factTypeMock.getId()) .setSourceObject(objectSource) .setDestinationObject(objectDestination), objectSource.getId()); Edge second = elementFactory.createEdge(new FactRecord() .setId(edgeID) .setTypeID(factTypeMock.getId()) .setSourceObject(objectSource) .setDestinationObject(objectDestination), objectSource.getId()); assertSame(first, second); }
@Test public void testCreateEdgeWithProperties() { FactTypeStruct factTypeMock = mockFactType(); ObjectTypeStruct objectTypeMock = mockObjectType(); ObjectRecord objectA = mockObject(objectTypeMock); ObjectRecord objectB = mockObject(objectTypeMock); FactRecord factRecord = new FactRecord() .setId(UUID.randomUUID()) .setTypeID(factTypeMock.getId()) .setBidirectionalBinding(true) .setDestinationObject(objectA) .setSourceObject(objectB); elementFactory.createEdge(factRecord, objectA.getId()); verify(propertyHelper).getFactProperties(factRecord, actGraph.getTraverseParams()); }