TransactionStrategyProvider implements StrategyProvider<TransactionStrategyExecutor> { @Override public TransactionStrategyExecutor rollbackStrategy() { return new TransactionStrategyExecutor() { @Override public void begin() { tx.begin(); } @Override public void commit() { if (tx.isActive()) { tx.rollback(); } } }; } TransactionStrategyProvider(final EntityTransaction tx); @Override TransactionStrategyExecutor rollbackStrategy(); @Override TransactionStrategyExecutor commitStrategy(); @Override TransactionStrategyExecutor disabledStrategy();  }
@Test public void testTransactionRollbackStrategyExecutionForActiveTransaction() throws Throwable { when(tx.isActive()).thenReturn(Boolean.TRUE); final TransactionStrategyExecutor executor = provider.rollbackStrategy(); executor.begin(); executor.commit(); verify(tx).begin(); verify(tx).isActive(); verify(tx).rollback(); verifyNoMoreInteractions(tx); }
@Test public void testTransactionRollbackStrategyExecutionWithoutActiveTransaction() throws Throwable { when(tx.isActive()).thenReturn(Boolean.FALSE); final TransactionStrategyExecutor executor = provider.rollbackStrategy(); executor.begin(); executor.commit(); verify(tx).begin(); verify(tx).isActive(); verifyNoMoreInteractions(tx); }