AbstractGraphTemplate implements GraphTemplate { @Override public <T> Optional<T> singleResult(String gremlin) { List<T> entities = query(gremlin); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.ofNullable(entities.get(0)); } throw new NonUniqueResultException("The gremlin query returns more than one result: " + gremlin); }  @Override T insert(T entity); @Override T update(T entity); @Override void delete(T idValue); @Override void deleteEdge(T idEdge); @Override Optional<T> find(ID idValue); @Override EdgeEntity edge(OUT outgoing, String label, IN incoming); @Override Optional<EdgeEntity> edge(E edgeId); @Override Collection<EdgeEntity> getEdges(T entity, Direction direction); @Override Collection<EdgeEntity> getEdges(T entity, Direction direction, String... labels); @SafeVarargs @Override final Collection<EdgeEntity> getEdges(T entity, Direction direction, Supplier<String>... labels); @Override Collection<EdgeEntity> getEdgesById(ID id, Direction direction, String... labels); @Override Collection<EdgeEntity> getEdgesById(ID id, Direction direction); @SafeVarargs @Override final Collection<EdgeEntity> getEdgesById(ID id, Direction direction, Supplier<String>... labels); @Override VertexTraversal getTraversalVertex(Object... vertexIds); @Override EdgeTraversal getTraversalEdge(Object... edgeIds); @Override Transaction getTransaction(); @Override List<T> query(String gremlin); @Override Optional<T> singleResult(String gremlin); @Override PreparedStatement prepare(String gremlin); @Override long count(String label); @Override long count(Class<T> entityClass);  }
@Test public void shouldReturnEmpty() { Optional<Person> person = getGraphTemplate().singleResult("g.V().hasLabel('Person')"); assertFalse(person.isPresent()); }