MemoryDataStore implements DataStore<K, E> { @Override public boolean save(K key, E entity) { if (key == null) { log.error("Asked to save an entity with a null key"); throw new DataStoreException(entityType, "Cannot save an entity with a null key"); } else if (entity == null) { log.error("Asked to save a null value into the data store"); throw new DataStoreException(entityType, "Cannot save a null entity"); } log.info("Attempting to save entity with key " + key); boolean saved = store.put(key, entity) == null; log.debug("Entity was " + (!saved ? "not " : "") + "saved under key " + key); return saved; } 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 testSavingWithNullKey() { dataStore.save(null, new Person()); }
@Test(expectedExceptions = DataStoreException.class) public void testSavingWithNullEntity() { dataStore.save("1", null); }