DefaultEdgeTraversal extends AbstractEdgeTraversal implements EdgeTraversal { @Override public Optional<EdgeEntity> getSingleResult() { List<EdgeEntity> result = getResultList(); if(result.isEmpty()) { return Optional.empty(); }else if(result.size() == 1) { return Optional.of(result.get(0)); } throw new NonUniqueResultException("The Edge traversal query returns more than one result"); } DefaultEdgeTraversal(Supplier<GraphTraversal<?, ?>> supplier,
                         Function<GraphTraversal<?, ?>, GraphTraversal<Vertex, Edge>> flow,
                         GraphConverter converter); @Override EdgeTraversal has(String propertyKey); @Override EdgeTraversal has(String propertyKey, Object value); @Override EdgeTraversal has(String propertyKey, P<?> predicate); @Override EdgeTraversal has(T accessor, Object value); @Override EdgeTraversal has(T accessor, P<?> predicate); @Override EdgeTraversal hasNot(String propertyKey); @Override EdgeTraversal filter(Predicate<EdgeEntity> predicate); @Override EdgeTraversal limit(long limit); @Override EdgeTraversal range(long start, long end); @Override EdgeRepeatTraversal repeat(); @Override VertexTraversal inV(); @Override VertexTraversal outV(); @Override VertexTraversal bothV(); @Override Optional<EdgeEntity> next(); @Override Optional<EdgeEntity> getSingleResult(); @Override List<EdgeEntity> getResultList(); @Override Stream<EdgeEntity> stream(); @Override Stream<EdgeEntity> next(int limit); @Override ValueMapTraversal valueMap(String... propertyKeys); @Override EdgeTraversalOrder orderBy(String property); @Override long count();  }
@Test public void shouldReturnErrorWhenThereAreMoreThanOneInGetSingleResult() { assertThrows(NonUniqueResultException.class, () -> graphTemplate.getTraversalEdge().getSingleResult()); }
@Test public void shouldReturnOptionalEmptyWhenThereIsNotResultInSingleResult() { Optional<EdgeEntity> entity = graphTemplate.getTraversalEdge(-1L).getSingleResult(); assertFalse(entity.isPresent()); }
@Test public void shouldReturnSingleResult() { String name = "Poliana"; Optional<EdgeEntity> entity = graphTemplate.getTraversalEdge(reads.getId().get()).getSingleResult(); assertEquals(reads, entity.get()); }