### Question:
InMemoryDatabaseTemplate extends AbstractDatabaseTemplate implements Resettable { @Override public <T extends Item> Collection<T> fetch(final Query query, final Class<T> itemClass) { if (query instanceof AttributeQuery) { return executeQuery((AttributeQuery) query, itemClass); } else if (query instanceof KeySetQuery) { return executeQuery((KeySetQuery) query, itemClass); } else { throw new UnsupportedQueryException(query.getClass()); } } InMemoryDatabaseTemplate(final DatabaseSchemaHolder databaseSchemaHolder); @Override T read(final ItemId itemId, final Class<T> itemClass); @Override T create(final T item,
            final PersistenceExceptionHandler<?>... persistenceExceptionHandlers); @SuppressWarnings("unchecked") @Override T update(final T item,
            final PersistenceExceptionHandler<?>... persistenceExceptionHandlers); @Override void delete(final Item item, final PersistenceExceptionHandler<?>... persistenceExceptionHandlers); @Override Collection<T> fetch(final Query query, final Class<T> itemClass); @Override GeneratedKeyHolder generateKeys(final SequenceKeyGenerator sequenceKeyGenerator); @Override void reset();  }### Answer:
@Test public void shouldFetch_withNoIds() { final InMemoryDatabaseTemplate databaseTemplate = new InMemoryDatabaseTemplate(databaseSchemaHolder); final Set<ItemId> itemIds = new HashSet<>(); final KeySetQuery query = new KeySetQuery(itemIds); final Collection<StubItem> returnedItems = databaseTemplate.fetch(query, StubItem.class); assertNotNull(returnedItems); assertEquals(0, returnedItems.size()); }
@Test public void shouldFetch_withUnknownIds() { final InMemoryDatabaseTemplate databaseTemplate = new InMemoryDatabaseTemplate(databaseSchemaHolder); final Set<ItemId> unknownIds = new HashSet<>(); final int idCount = 1 + Randoms.randomInt(5); for (int n = 0; n < idCount; n++) { unknownIds.add(new ItemId(Randoms.randomId())); } final KeySetQuery query = new KeySetQuery(unknownIds); final Collection<StubItem> returnedItems = databaseTemplate.fetch(query, StubItem.class); assertNotNull(returnedItems); assertEquals(0, returnedItems.size()); }
@Test public void shouldGetEmptySet_withNullAttributeQuery() { final String stringProperty = null; final Query query = new AttributeQuery(STRING_PROPERTY, new Condition(Operators.EQUALS, stringProperty)); final InMemoryDatabaseTemplate databaseTemplate = new InMemoryDatabaseTemplate(databaseSchemaHolder); final Collection<StubItem> itemResults = databaseTemplate.fetch(query, StubItem.class); assertNotNull(itemResults); assertEquals(0, itemResults.size()); }
@Test public void shouldGetEmptySet_withEmptyAttributeQuery() { final String stringProperty = ""; final Query query = new AttributeQuery(STRING_PROPERTY, new Condition(Operators.EQUALS, stringProperty)); final InMemoryDatabaseTemplate databaseTemplate = new InMemoryDatabaseTemplate(databaseSchemaHolder); final Collection<StubItem> itemResults = databaseTemplate.fetch(query, StubItem.class); assertNotNull(itemResults); assertEquals(0, itemResults.size()); }