### Question:
NeighborCache implements GraphListener<V, E> { public List<V> neighborListOf(V v) { Neighbors<V> nbrs = neighbors.get(v); if (nbrs == null) { nbrs = new Neighbors<>(Graphs.neighborListOf(graph, v)); neighbors.put(v, nbrs); } return nbrs.getNeighborList(); } NeighborCache(Graph<V, E> graph); Set<V> predecessorsOf(V v); Set<V> successorsOf(V v); Set<V> neighborsOf(V v); List<V> neighborListOf(V v); @Override void edgeAdded(GraphEdgeChangeEvent<V, E> e); @Override void edgeRemoved(GraphEdgeChangeEvent<V, E> e); @Override void vertexAdded(GraphVertexChangeEvent<V> e); @Override void vertexRemoved(GraphVertexChangeEvent<V> e);  }### Answer:
@Test public void testNeighborListCreation() { ListenableGraph<String, DefaultEdge> graph = new DefaultListenableGraph<>(new SimpleGraph<>(DefaultEdge.class)); final String A = "A"; final String B = "B"; final String C = "C"; final String D = "D"; NeighborCache<String, DefaultEdge> cache = new NeighborCache<>(graph); graph.addGraphListener(cache); graph.addVertex(A); graph.addVertex(B); graph.addVertex(C); graph.addVertex(D); graph.addEdge(D, A); graph.addEdge(D, B); graph.addEdge(D, C); assertThat(cache.neighborListOf(B), hasItems(D)); assertThat(cache.neighborListOf(B).size(), is(1)); graph.addEdge(A, B); assertThat(cache.neighborListOf(B), hasItems(A, D)); assertThat(cache.neighborListOf(B).size(), is(2)); graph.removeEdge(D, B); assertThat(cache.neighborListOf(B), hasItems(A)); assertThat(cache.neighborListOf(B).size(), is(1)); graph.removeVertex(B); exception.expect(IllegalArgumentException.class); exception.expectMessage("no such vertex"); cache.neighborListOf(B); }