### Question:
ServerRuntime extends CayenneRuntime { public <T> T performInTransaction(TransactionalOperation<T> op) { TransactionManager tm = injector.getInstance(TransactionManager.class); return tm.performInTransaction(op); } protected  ServerRuntime(Collection<Module> modules); static ServerRuntimeBuilder builder(); static ServerRuntimeBuilder builder(String name); T performInTransaction(TransactionalOperation<T> op); T performInTransaction(TransactionalOperation<T> op, TransactionListener callback); DataDomain getDataDomain(); DataSource getDataSource(); DataSource getDataSource(String dataNodeName);  }### Answer:
@Test public void testPerformInTransaction() { final BaseTransaction tx = mock(BaseTransaction.class); final TransactionFactory txFactory = mock(TransactionFactory.class); when(txFactory.createTransaction()).thenReturn(tx); when(txFactory.createTransaction(any(TransactionDescriptor.class))).thenReturn(tx); Module module = binder -> binder.bind(TransactionFactory.class).toInstance(txFactory); ServerRuntime runtime = ServerRuntime.builder().addConfig("xxxx").addModule(module).build(); try { final Object expectedResult = new Object(); Object result = runtime.performInTransaction(new TransactionalOperation<Object>() { public Object perform() { assertSame(tx, BaseTransaction.getThreadTransaction()); return expectedResult; } }); assertSame(expectedResult, result); } finally { runtime.shutdown(); } }