### Question:
IdIndexChangeListener implements ChangeListener { @Override public void onPropertyUpdate(Collection collection, Optional<Vertex> oldVertex, Vertex newVertex) { indexHandler.upsertIntoIdIndex(UUID.fromString(newVertex.value("tim_id")), newVertex); } IdIndexChangeListener(IndexHandler indexHandler); @Override void onCreate(Collection collection, Vertex vertex); @Override void onPropertyUpdate(Collection collection, Optional<Vertex> oldVertex, Vertex newVertex); @Override void onRemoveFromCollection(Collection collection, Optional<Vertex> oldVertex, Vertex newVertex); @Override void onAddToCollection(Collection collection, Optional<Vertex> oldVertex, Vertex newVertex); @Override void onCreateEdge(Collection collection, Edge edge); @Override void onEdgeUpdate(Collection collection, Edge oldEdge, Edge newEdge);  }### Answer:
@Test public void onPropertyUpdateRemovesTheOldVertexFromTheIdIndexBeforeAddingTheNewOne() { UUID timId = UUID.randomUUID(); Vertex oldVertex = vertexWithId(timId); Vertex newVertex = vertexWithId(timId); instance.onPropertyUpdate(NULL_COLLECTION, Optional.of(oldVertex), newVertex); verify(indexHandler).upsertIntoIdIndex(timId, newVertex); }
@Test public void onPropertyUpdateDoesNotRemoveTheOldVertexWhenTheOptionalIsEmpty() { UUID timId = UUID.randomUUID(); Vertex newVertex = vertexWithId(timId); instance.onPropertyUpdate(NULL_COLLECTION, Optional.empty(), newVertex); verify(indexHandler, never()).removeFromIdIndex(any(Vertex.class)); }