### Question:
RelationshipUtils { public static Relationship createRelationshipIfNotExists(Node node1, Node node2, RelationshipType type, Direction direction) { Relationship existing = getSingleRelationshipOrNull(node1, node2, type, direction); if (existing == null) { if (Direction.INCOMING.equals(direction)) { return node2.createRelationshipTo(node1, type); } return node1.createRelationshipTo(node2, type); } return existing; } private  RelationshipUtils(); static Relationship getSingleRelationship(Node node1, Node node2, RelationshipType type, Direction direction); static Relationship getSingleRelationshipOrNull(Node node1, Node node2, RelationshipType type, Direction direction); static boolean relationshipNotExists(Node node1, Node node2, RelationshipType type, Direction direction); static boolean relationshipExists(Node node1, Node node2, RelationshipType type, Direction direction); static void deleteRelationshipIfExists(Node node1, Node node2, RelationshipType type, Direction direction); static Relationship createRelationshipIfNotExists(Node node1, Node node2, RelationshipType type, Direction direction);  }### Answer:
@Test public void existingRelationshipShouldNotBeRecreated() { try (Transaction tx = database.beginTx()) { Node node1 = database.getNodeById(0); Node node2 = database.getNodeById(1); Relationship r = createRelationshipIfNotExists(node1, node2, withName("TEST"), OUTGOING); assertEquals(0, r.getId()); assertEquals(1, IterableUtils.count(database.getAllRelationships())); tx.success(); } }