EventPublishingDataStore implements DataStore<K, E>, DataStoreEventPublisher { @Override public Collection<K> keys() { return delegate.keys(); } EventPublishingDataStore(DataStore<K, E> delegate, RepositoryMetadata repositoryMetadata,
                                    DataStoreEventListenerContext listenerContext); @Override boolean hasKey(K key); @Override boolean save(K key, E entity); @Override boolean delete(K key); @Override E retrieve(K key); @Override Collection<K> keys(); @Override Collection<E> retrieveAll(); @Override Class<E> getEntityType(); @Override void truncate(); @Override void publishEvent(DataStoreEvent event);  }
@Test public void testKeysDelegation() { final AtomicBoolean called = new AtomicBoolean(false); final DataStore<String, Person> localDataStore = new EventPublishingDataStore<>( new MemoryDataStore<String, Person>(Person.class) { @Override public Collection<String> keys() { called.set(true); return super.keys(); } }, repositoryMetadata, listenerContext); assertThat(called.get(), is(false)); localDataStore.keys(); assertThat(called.get(), is(true)); }