У меня есть код, в котором используется диспетчер синхронизации syschronisation .. но я не могу заставить его работать в mocks .. im mocking менеджер сущностей и диспетчер транзакций .. так что мой контекст сохраняет сущность и вызов commit ... TransactionSynchronizationManager, похоже, не попадает ... в тесте?Junit и Jmock для проверки Springs 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();
}
пожалуйста, очистить свой пост – nav0611
да? .. как .. подробнее ... лучше форматирования? ... – user1555190
Его сейчас отформатирован Дон Роби – nav0611