### Question:
InMemoryBatchDatabaseTemplate extends InMemoryDatabaseTemplate implements BatchDatabaseTemplate { @Override public <T extends Item> List<T> batchWrite(final List<T> items, final Class<T> itemClass) { final List<T> updatedItems = new ArrayList<>(); for (final T item : items) { final T updatedItem = update(item); updatedItems.add(updatedItem); } return updatedItems; } InMemoryBatchDatabaseTemplate(final DatabaseSchemaHolder databaseSchemaHolder); @Override List<T> batchWrite(final List<T> items, final Class<T> itemClass);  }### Answer:
@Test public void shouldCreate_viaBatchWrite_withSingleItem() { final InMemoryBatchDatabaseTemplate databaseTemplate = new InMemoryBatchDatabaseTemplate(databaseSchemaHolder); final StubItem stubItem = dataGenerator.randomStubItem(); stubItem.setVersion(null); final List<StubItem> stubItems = new ArrayList<StubItem>(); stubItems.add(stubItem); final List<StubItem> successfulStubItems = databaseTemplate.batchWrite(stubItems, StubItem.class); for (final StubItem aStubItem : successfulStubItems) { assertEquals(new Long(1), aStubItem.getVersion()); for (final StubItem initialStubItem : stubItems) { if (aStubItem.getId().equals(initialStubItem.getId())) { assertEquals(aStubItem.getStringProperty(), initialStubItem.getStringProperty()); assertEquals(aStubItem.getStringSetProperty(), initialStubItem.getStringSetProperty()); } } } }
@Test public void shouldUpdate_viaBatchWrite_withSingleItem() { final InMemoryBatchDatabaseTemplate databaseTemplate = new InMemoryBatchDatabaseTemplate(databaseSchemaHolder); final StubItem createdItem = dataGenerator.randomStubItem(); databaseTemplate.create(createdItem); final Long originalVersion = createdItem.getVersion(); final String stringProperty = randomString(10); final String stringProperty2 = randomString(10); final Set<String> newStringSetProperty = Sets.newSet(randomString(10), randomString(10), randomString(10)); createdItem.setStringProperty(stringProperty); createdItem.setStringProperty2(stringProperty2); createdItem.setStringSetProperty(newStringSetProperty); final Long newVersion = originalVersion + 1; final List<StubItem> stubItems = new ArrayList<StubItem>(); stubItems.add(createdItem); final List<StubItem> successfulStubItems = databaseTemplate.batchWrite(stubItems, StubItem.class); for (final StubItem aStubItem : successfulStubItems) { assertEquals(newVersion, aStubItem.getVersion()); assertEquals(createdItem.getId(), aStubItem.getId()); assertEquals(stringProperty, aStubItem.getStringProperty()); assertEquals(stringProperty2, aStubItem.getStringProperty2()); assertEquals(newStringSetProperty, aStubItem.getStringSetProperty()); } }
@Test public void shouldUpdate_viaBatchWrite_withSingleItemWithCompoundPk() { final InMemoryBatchDatabaseTemplate databaseTemplate = new InMemoryBatchDatabaseTemplate(databaseSchemaHolder); final StubWithRangeItem createdItem = dataGenerator.randomStubWithRangeItem(); databaseTemplate.create(createdItem); final Long originalVersion = createdItem.getVersion(); final String stringProperty = randomString(10); final boolean booleanProperty = randomBoolean(); final Set<String> newStringSetProperty = Sets.newSet(randomString(10), randomString(10), randomString(10)); createdItem.setStringProperty(stringProperty); createdItem.setBooleanProperty(booleanProperty); createdItem.setStringSetProperty(newStringSetProperty); final Long newVersion = originalVersion + 1; final List<StubWithRangeItem> stubWithRangeItems = new ArrayList<StubWithRangeItem>(); stubWithRangeItems.add(createdItem); final List<StubWithRangeItem> successfulStubWithRangeItems = databaseTemplate.batchWrite(stubWithRangeItems, StubWithRangeItem.class); for (final StubWithRangeItem aStubWithRangeItem : successfulStubWithRangeItems) { assertEquals(newVersion, aStubWithRangeItem.getVersion()); assertEquals(createdItem.getId(), aStubWithRangeItem.getId()); assertEquals(stringProperty, aStubWithRangeItem.getStringProperty()); assertEquals(booleanProperty, aStubWithRangeItem.isBooleanProperty()); assertEquals(newStringSetProperty, aStubWithRangeItem.getStringSetProperty()); } }