### Question:
CypherUtil { String substituteRelationships(String query, final Multimap<String, Object> valueMap) { StrSubstitutor substitutor = new StrSubstitutor(new StrLookup<String>() { @Override public String lookup(String key) { Collection<String> resolvedRelationshipTypes = transform(valueMap.get(key), new Function<Object, String>() { @Override public String apply(Object input) { if (input.toString().matches(".*(\\s).*")) { throw new IllegalArgumentException( "Cypher relationship templates must not contain spaces"); } return curieUtil.getIri(input.toString()).orElse(input.toString()); } }); return on("|").join(resolvedRelationshipTypes); } }); return substitutor.replace(query); } @Inject  CypherUtil(GraphDatabaseService graphDb, CurieUtil curieUtil); Result execute(String query, Multimap<String, Object> params, long timeout, TimeUnit unit); Result execute(String query, long timeout, TimeUnit unit); Result execute(String query, Multimap<String, Object> params); Result execute(String query); Set<RelationshipType> getEntailedRelationshipTypes(Collection<String> parents); @Deprecated String resolveStartQuery(String cypher); String resolveNodeIris(String cypher); String resolveRelationships(String cypher); Map<String, String> getCurieMap();  }### Answer:
@Test public void substituteSingleRelationship() { Multimap<String, Object> valueMap = HashMultimap.create(); valueMap.put("node_id", "HP_123"); valueMap.put("rel_id", "RO_1"); String actual = util.substituteRelationships("({node_id})-[:${rel_id}!]-(end)", valueMap); assertThat(actual, is("({node_id})-[:RO_1!]-(end)")); }
@Test public void substituteCurieRelationship() { Multimap<String, Object> valueMap = HashMultimap.create(); valueMap.put("node_id", "HP_123"); valueMap.put("rel_id", "FOO:foo"); String actual = util.substituteRelationships("({node_id})-[:${rel_id}!]-(end)", valueMap); assertThat(actual, is("({node_id})-[:http: }
@Test public void substituteMultipleRelationships() { Multimap<String, Object> valueMap = HashMultimap.create(); valueMap.put("node_id", "HP_123"); valueMap.put("rel_id", "RO_1"); valueMap.put("rel_id", "RO_2"); String actual = util.substituteRelationships("({node_id})-[:${rel_id}!]-(end)", valueMap); assertThat(actual, isOneOf("({node_id})-[:RO_2|RO_1!]-(end)", "({node_id})-[:RO_1|RO_2!]-(end)")); }
@Test public void naiveInjectionPrevention() { Multimap<String, Object> valueMap = HashMultimap.create(); valueMap.put("node_id", "HP_123"); valueMap.put("rel_id", "DELETE *"); exception.expect(IllegalArgumentException.class); util.substituteRelationships("({node_id})-[:${rel_id}!]-(end)", valueMap); }