MemoryDataStore implements DataStore<K, E> { @Override public E retrieve(K key) { if (key == null) { log.error("Asked to retrieve an entity from a null key"); throw new DataStoreException(entityType, "Cannot retrieve an entity with a null key"); } if (store.containsKey(key)) { log.info("Retrieving entity from key " + key); return store.get(key); } else { log.info("No entity was found to return under key " + key); } return null; } MemoryDataStore(Class<E> entityType); @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 synchronized Collection<E> retrieveAll(); @Override Class<E> getEntityType(); @Override void truncate();  }
@Test(expectedExceptions = DataStoreException.class) public void testRetrievingWithNullKey() { dataStore.retrieve(null); }