### Question:
FluentTransaction { public Intermediate with(Callable<R> content){ txContent = content; return new Intermediate(); } private  FluentTransaction(TransactionManager txManager); static FluentTransaction transaction(TransactionManager txManager); TransactionManager getTransactionManager(); Intermediate with(Callable<R> content);  }### Answer:
@Test public void shouldCallBeginCommitCloseWhenTransactionIsExecuted() throws Exception{ ftx.with(content).onRolledBack(rolledBackHandler).execute(); verify(txManager).begin(); verify(txManager).commit(); verify(txManager).close(); verifyNoMoreInteractions(txManager); verify(content).call(); verifyNoMoreInteractions(content); verifyZeroInteractions(rolledBackHandler); }
@Test public void shouldCallOnCommittedCallBackWhenTransactionWithOnCommitedIsExecuted() throws Exception{ ftx.with(content).onRolledBack(rolledBackHandler).onCommitted(committedHandler).execute(); verify(txManager).begin(); verify(txManager).commit(); verify(txManager).close(); verifyNoMoreInteractions(txManager); verify(content).call(); verify(committedHandler).committed(any(Object.class)); verifyNoMoreInteractions(committedHandler); verifyNoMoreInteractions(content); verifyZeroInteractions(rolledBackHandler); }
@Test public void shouldCallBeginRollBackCloseWhenTransactionIsExecutedAndFail() throws Exception{ when(content.call()).thenThrow(new Exception()); ftx.with(content).onRolledBack(rolledBackHandler).execute(); verify(txManager).begin(); verify(txManager).close(); verify(txManager).rollback(); verifyNoMoreInteractions(txManager); verify(content).call(); verifyNoMoreInteractions(content); verify(rolledBackHandler).rolledBack(any(Exception.class)); verifyZeroInteractions(rolledBackHandler); }