我有一些使用事务同步管理器的代码..但我似乎无法让它在模拟中工作..我在模拟实体管理器和事务管理器..以便我的上下文保存一个实体并调用提交...... TransactionSynchronizationManager 确实似乎没有被击中……在测试中?
this.transactionTemplate.execute(new TransactionCallback<E>() {
@Override
public E doInTransaction(TransactionStatus status) {
// update entities
TransactionSynchronizationManager.registerSynchronization(new NotificationTransactionSynchronization(){
@Override
public void afterCommit() {
// do some post commit work
int i = notifier.notifyAllListeners();
}
});
}
});
我的测试课:
@Test
public void testHappyPath() {
context.checking(new Expectations() {
{
allowing(platformTransactionManager).getTransaction(definition);
will((returnValue(status)));
oneOf(platformTransactionManager).commit(status);
//next line never gets hit... so the test fails...
//if i remove it will pass but i need to check that it works...
oneOf(mockNotifier).notifyAllListeners();
}
});
this.TestClass.process();
context.assertIsSatisfied();
}