### Question:
NeighborsFinder { public Set<Node> findNeighbors(Node node1, Node node2, RelationshipType relationshipType, Direction direction) { Set<Node> node1Neighbors = findNeighbors(node1, relationshipType, direction); Set<Node> node2Neighbors = findNeighbors(node2, relationshipType, direction); node1Neighbors.addAll(node2Neighbors); return node1Neighbors; } NeighborsFinder(); Set<Node> findCommonNeighbors(Node node1, Node node2, RelationshipType relationshipType, Direction direction); Set<Node> findNeighbors(Node node1, Node node2, RelationshipType relationshipType, Direction direction); Set<Node> findNeighbors(Node node, RelationshipType relationshipType, Direction direction);  }### Answer:
@Test void dontCountDuplicates() { runInTransaction(db, tx -> { Node[] nodes = new Node[4]; nodes[0] = tx.createNode(); nodes[1] = tx.createNode(); nodes[2] = tx.createNode(); nodes[3] = tx.createNode(); nodes[0].createRelationshipTo(nodes[2], FRIEND); nodes[1].createRelationshipTo(nodes[2], FRIEND); nodes[0].createRelationshipTo(nodes[3], COLLEAGUE); nodes[1].createRelationshipTo(nodes[3], COLLEAGUE); NeighborsFinder neighborsFinder = new NeighborsFinder(); Set<Node> neighbors = neighborsFinder.findNeighbors(nodes[0], nodes[1], null, Direction.BOTH); assertEquals(2, neighbors.size()); assertThat(neighbors, hasItems(nodes[2], nodes[3])); }); }
@Test void otherNodeCountsAsNeighbor() { runInTransaction(db, tx -> { Node[] nodes = new Node[2]; nodes[0] = tx.createNode(); nodes[1] = tx.createNode(); nodes[0].createRelationshipTo(nodes[1], FRIEND); NeighborsFinder neighborsFinder = new NeighborsFinder(); Set<Node> neighbors = neighborsFinder.findNeighbors(nodes[0], nodes[1], null, Direction.BOTH); assertEquals(2, neighbors.size()); assertThat(neighbors, hasItems(nodes[0], nodes[1])); }); }
@Test void otherNodeCountsAsOutgoingNeighbor() { Node[] nodes = new Node[2]; runInTransaction(db, tx -> { nodes[0] = tx.createNode(); nodes[1] = tx.createNode(); nodes[0].createRelationshipTo(nodes[1], FRIEND); NeighborsFinder neighborsFinder = new NeighborsFinder(); Set<Node> neighbors = neighborsFinder.findNeighbors(nodes[0], nodes[1], null, Direction.OUTGOING); assertEquals(1, neighbors.size()); assertThat(neighbors, hasItems(nodes[1])); }); }