### Question:
ObjectVertex implements Vertex { static boolean matchesDirection(FactRecord fact, ObjectRecord object, Direction direction) { ObjectRecord sourceObject = fact.getSourceObject(); ObjectRecord destinationObject = fact.getDestinationObject(); if (sourceObject == null || destinationObject == null) return false; boolean isLoop = Objects.equals(sourceObject.getId(), destinationObject.getId()); if (isLoop) return false; boolean matchesBidirectional = (fact.isBidirectionalBinding() || direction == BOTH); return matchesBidirectional || (Objects.equals(object.getId(), sourceObject.getId()) && direction == OUT) || (Objects.equals(object.getId(), destinationObject.getId()) && direction == IN); } private  ObjectVertex(ActGraph graph,
                       ObjectRecord object,
                       ObjectFactTypeResolver.ObjectTypeStruct type,
                       List<PropertyEntry<?>> properties); @Override Edge addEdge(String label, Vertex inVertex, Object... keyValues); @Override Iterator<Edge> edges(Direction direction, String... edgeLabels); @Override Iterator<Vertex> vertices(Direction direction, String... edgeLabels); @Override Iterator<VertexProperty<V>> properties(String... propertyKeys); @Override VertexProperty<V> property(VertexProperty.Cardinality cardinality, String key, V value, Object... keyValues); @Override Object id(); @Override String label(); @Override Graph graph(); @Override void remove(); ObjectRecord getObjectRecord(); static Builder builder(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@Test public void testMatchesDirectionBidirectional() { ObjectRecord objectA = new ObjectRecord().setId(UUID.randomUUID()); ObjectRecord objectB = new ObjectRecord().setId(UUID.randomUUID()); FactRecord bidirectionalFact = new FactRecord() .setId(UUID.randomUUID()) .setBidirectionalBinding(true) .setSourceObject(objectA) .setDestinationObject(objectB); assertTrue(ObjectVertex.matchesDirection(bidirectionalFact, objectA, OUT)); assertTrue(ObjectVertex.matchesDirection(bidirectionalFact, objectA, IN)); assertTrue(ObjectVertex.matchesDirection(bidirectionalFact, objectA, BOTH)); }
@Test public void testMatchesDirectionIgnoresLoops() { ObjectRecord objectA = new ObjectRecord().setId(UUID.randomUUID()); FactRecord loopFact = new FactRecord() .setId(UUID.randomUUID()) .setSourceObject(objectA) .setDestinationObject(objectA); assertFalse(ObjectVertex.matchesDirection(loopFact, objectA, OUT)); assertFalse(ObjectVertex.matchesDirection(loopFact, objectA, IN)); assertFalse(ObjectVertex.matchesDirection(loopFact, objectA, BOTH)); }
@Test public void testMatchesDirectionIgnoresOneLeggedFacts() { ObjectRecord objectA = new ObjectRecord().setId(UUID.randomUUID()); FactRecord loopFact = new FactRecord() .setId(UUID.randomUUID()) .setDestinationObject(objectA); assertFalse(ObjectVertex.matchesDirection(loopFact, objectA, OUT)); assertFalse(ObjectVertex.matchesDirection(loopFact, objectA, IN)); assertFalse(ObjectVertex.matchesDirection(loopFact, objectA, BOTH)); }
@Test public void testMatchesDirectionUniDir() { ObjectRecord objectA = new ObjectRecord().setId(UUID.randomUUID()); ObjectRecord objectB = new ObjectRecord().setId(UUID.randomUUID()); FactRecord aToBFact = new FactRecord() .setId(UUID.randomUUID()) .setSourceObject(objectA) .setDestinationObject(objectB); assertTrue(ObjectVertex.matchesDirection(aToBFact, objectA, OUT)); assertFalse(ObjectVertex.matchesDirection(aToBFact, objectA, IN)); assertTrue(ObjectVertex.matchesDirection(aToBFact, objectA, BOTH)); FactRecord bToAFact = new FactRecord() .setId(UUID.randomUUID()) .setSourceObject(objectB) .setDestinationObject(objectA); assertFalse(ObjectVertex.matchesDirection(bToAFact, objectA, OUT)); assertTrue(ObjectVertex.matchesDirection(bToAFact, objectA, IN)); assertTrue(ObjectVertex.matchesDirection(bToAFact, objectA, BOTH)); }