DefaultValueMapTraversal implements ValueMapTraversal { @Override public Optional<Map<String, Object>> getSingleResult() { List<Map<String, Object>> result = getResultList(); if (result.isEmpty()) { return Optional.empty(); } if (result.size() == 1) { return Optional.of(result.get(0)); } throw new NonUniqueResultException("The Edge traversal query returns more than one result"); } DefaultValueMapTraversal(Supplier<GraphTraversal<?, ?>> supplier, Function<GraphTraversal<?, ?>,
            GraphTraversal<Vertex, Map<String, Object>>> flow); @Override Stream<Map<String, Object>> stream(); @Override Stream<Map<String, Object>> next(int limit); @Override Map<String, Object> next(); @Override Optional<Map<String, Object>> getSingleResult(); @Override List<Map<String, Object>> getResultList(); @Override long count();  }
@Test public void shouldReturnErrorWhenThereAreMoreThanOneInGetSingleResult() { assertThrows(NonUniqueResultException.class, () -> graphTemplate.getTraversalVertex() .hasLabel(Person.class).valueMap("name") .getSingleResult()); }
@Test public void shouldReturnOptionalEmptyWhenThereIsNotResultInSingleResult() { Optional<Map<String, Object>> entity = graphTemplate.getTraversalVertex() .hasLabel("not_found").valueMap("name").getSingleResult(); assertFalse(entity.isPresent()); }
@Test public void shouldReturnSingleResult() { String name = "Poliana"; Optional<Map<String, Object>> poliana = graphTemplate.getTraversalVertex().hasLabel("Person"). has("name", name).valueMap("name").getSingleResult(); assertEquals(name, poliana.map(m -> List.class.cast(m.get("name")).get(0)).orElse("")); }