@Test
public void runInTransactionWithRetriesShouldCallFunction() throws Exception {

  final DatastoreStorage storage = new DatastoreStorage(datastore, storageTransactionFactory,
      executor, logger);
  final CheckedDatastoreTransaction transaction = datastore.newTransaction();
  final DatastoreStorageTransaction storageTransaction = spy(new DatastoreStorageTransaction(transaction));
  when(storageTransactionFactory.apply(any())).thenReturn(storageTransaction);
  when(transactionFunction.apply(any())).thenReturn("foo");
  String result = storage.runInTransactionWithRetries(transactionFunction);
  assertThat(result, is("foo"));
  verify(transactionFunction).apply(storageTransaction);
}