### Question:
Neo4jLuceneEntityFetcher extends GremlinEntityFetcher { public GraphTraversal<Vertex, Vertex> getEntity(GraphTraversalSource source, UUID id, Integer rev, String collectionName) { if (rev == null) { Optional<Vertex> foundVertex = getVertexByIndex(source, id, collectionName); if (foundVertex.isPresent()) { return source.V(foundVertex.get().id()); } } return super.getEntity(source, id, rev, collectionName); } Neo4jLuceneEntityFetcher(TinkerPopGraphManager graphManager, IndexHandler indexHandler); GraphTraversal<Vertex, Vertex> getEntity(GraphTraversalSource source, UUID id, Integer rev,
                                                  String collectionName); static final int MAX_VERSION_OF_DEPTH; }### Answer:
@Test public void getEntityRetrievesTheLatestFromTheGraphEvenIfTheIndexIsNotUpToDate() { final UUID timId = UUID.randomUUID(); final String collectionName = "things"; TinkerPopGraphManager graphManager = newGraph() .withVertex("latest", v -> v .withTimId(timId) .isLatest(true)) .withVertex(v -> v .withTimId(timId) .isLatest(false) .withOutgoingRelation("VERSION_OF", "latest") ) .wrap(); GraphTraversal<Vertex, Vertex> secondLatestVertexT = graphManager.getGraph() .traversal().V() .has("tim_id", timId.toString()) .has("isLatest", false); given(indexHandler.findById(timId)).willReturn(Optional.of(secondLatestVertexT.next())); Neo4jLuceneEntityFetcher instance = new Neo4jLuceneEntityFetcher(graphManager, indexHandler); GraphTraversalSource traversal = graphManager.getGraph().traversal(); GraphTraversal<Vertex, Vertex> entityT = instance.getEntity(traversal, timId, null, collectionName); assertThat(entityT.hasNext(), is(true)); assertThat(entityT.next(), is(likeVertex().withTimId(timId).withProperty("isLatest", true))); }
@Test public void getEntityRetrievesTheVertexDirectFromTheDatabaseWhenTheIndexDoesNotContainIt() { final UUID timId = UUID.randomUUID(); final String things = "things"; TinkerPopGraphManager graphManager = newGraph() .withVertex("latest", v -> v .withTimId(timId) .isLatest(true)) .withVertex(v -> v .withTimId(timId) .isLatest(false) .withOutgoingRelation("VERSION_OF", "latest") ) .wrap(); given(indexHandler.findById(timId)).willReturn(Optional.empty()); Neo4jLuceneEntityFetcher instance = new Neo4jLuceneEntityFetcher(graphManager, indexHandler); GraphTraversalSource traversal = graphManager.getGraph().traversal(); GraphTraversal<Vertex, Vertex> entityT = instance.getEntity(traversal, timId, null, things); assertThat(entityT.next().value("tim_id"), equalTo(timId.toString())); }