### Question:
InMemoryDatabaseTemplate extends AbstractDatabaseTemplate implements Resettable { @Override public GeneratedKeyHolder generateKeys(final SequenceKeyGenerator sequenceKeyGenerator) { final Collection<Long> keys = new ArrayList<>(); final int keyCount = sequenceKeyGenerator.keyCount(); final long startingKey = ATOMIC_COUNTER.getAndAdd(keyCount) + 1; for (int i = 0; i < keyCount; i++) { keys.add(startingKey + i); } return new GeneratedKeyHolder(keys); } 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 shouldGenerateKeyHolder_withSequenceKeyGenerator() { final int keyCount = 1 + Randoms.randomInt(100); final SequenceKeyGenerator sequenceKeyGenerator = new SequenceKeyGenerator(randomString(), keyCount); final InMemoryDatabaseTemplate databaseTemplate = new InMemoryDatabaseTemplate(databaseSchemaHolder); final GeneratedKeyHolder genratedKeyHolder = databaseTemplate.generateKeys(sequenceKeyGenerator); assertNotNull(genratedKeyHolder); assertThat(genratedKeyHolder.keys().size(), Is.is(sequenceKeyGenerator.keyCount())); final Set<Long> setOfKeysToCheckForDuplicates = new HashSet<>(genratedKeyHolder.keys()); assertThat(setOfKeysToCheckForDuplicates.size(), Is.is(genratedKeyHolder.keys().size())); }
@Test public void shouldUniquelyGenerateKeyHolders_withManySequenceKeyGenerator() { final Collection<SequenceKeyGenerator> sequnceKeyGeneratorCollection = new ArrayList<>(); final Collection<GeneratedKeyHolder> generatedKeyHolderCollection = new ArrayList<>(); int totalKeyCount = 0; for (int i = 0; i < randomInt(9) + 1; i++) { final int keyCount = 1 + Randoms.randomInt(100); totalKeyCount += keyCount; final SequenceKeyGenerator sequenceKeyGenerator = new SequenceKeyGenerator(randomString(), keyCount); sequnceKeyGeneratorCollection.add(sequenceKeyGenerator); } final InMemoryDatabaseTemplate databaseTemplate = new InMemoryDatabaseTemplate(databaseSchemaHolder); for (final SequenceKeyGenerator sequenceKeyGenerator : sequnceKeyGeneratorCollection) { generatedKeyHolderCollection.add(databaseTemplate.generateKeys(sequenceKeyGenerator)); } assertFalse(generatedKeyHolderCollection.isEmpty()); final Set<Long> allGeneratedKeys = new HashSet<>(); for (final GeneratedKeyHolder generatedKeyHolder : generatedKeyHolderCollection) { allGeneratedKeys.addAll(generatedKeyHolder.keys()); } assertTrue(allGeneratedKeys.size() == totalKeyCount); }