InstrumentedDatastore implements Datastore, InstrumentedDatastoreReaderWriter { @Override public Transaction newTransaction(TransactionOptions transactionOptions) { return InstrumentedTransaction.of(stats, delegate.newTransaction(transactionOptions)); } private  InstrumentedDatastore(Datastore delegate, Stats stats); @Override Transaction newTransaction(TransactionOptions transactionOptions); @Override Transaction newTransaction(); @Override T runInTransaction(TransactionCallable<T> transactionCallable); @Override T runInTransaction(TransactionCallable<T> transactionCallable, TransactionOptions transactionOptions); @Override Batch newBatch(); @Override Entity get(Key key, ReadOption... readOptions); @Override Iterator<Entity> get(Iterable<Key> keys, ReadOption... readOptions); @Override List<Entity> fetch(Iterable<Key> keys, ReadOption... readOptions); @Override QueryResults<T> run(Query<T> query, ReadOption... readOptions); @Override Key allocateId(IncompleteKey key); @Override List<Key> allocateId(IncompleteKey... keys); @Override Entity add(FullEntity<?> entity); @Override List<Entity> add(FullEntity<?>... entities); @Override void update(Entity... entities); @Override Entity put(FullEntity<?> entity); @Override List<Entity> put(FullEntity<?>... entities); @Override void delete(Key... keys); @Override KeyFactory newKeyFactory(); @Override DatastoreOptions getOptions(); @Override Stats stats(); @Override DatastoreReaderWriter readerWriter(); Datastore delegate(); static InstrumentedDatastore of(Datastore delegate, Stats stats);  }
@Test public void newTransaction() { when(datastore.newTransaction(any(TransactionOptions.class))).thenReturn(transaction); var transactionOptions = TransactionOptions.newBuilder().build(); var instrumented1 = instrumentedDatastore.newTransaction(transactionOptions); verify(datastore).newTransaction(transactionOptions); verifyNoMoreInteractions(datastore); reset(datastore); testTransaction(instrumented1); when(datastore.newTransaction()).thenReturn(transaction); var instrumented2 = instrumentedDatastore.newTransaction(); verify(datastore).newTransaction(); verifyNoMoreInteractions(datastore); reset(datastore); testTransaction(instrumented2); }