### Question:
ReplayableCommitProcess implements TransactionCommitProcess { @Override public long commit( TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode ) throws TransactionFailureException { long txId = lastLocalTxId.incrementAndGet(); if ( txId > transactionCounter.lastCommittedTransactionId() ) { return localCommitProcess.commit( batch, commitEvent, mode ); } return txId; } ReplayableCommitProcess( TransactionCommitProcess localCommitProcess, TransactionCounter transactionCounter ); @Override long commit( TransactionToApply batch,
                        CommitEvent commitEvent,
                        TransactionApplicationMode mode );  }### Answer:
@Test public void shouldCommitTransactions() throws Exception { TransactionToApply newTx1 = mock( TransactionToApply.class ); TransactionToApply newTx2 = mock( TransactionToApply.class ); TransactionToApply newTx3 = mock( TransactionToApply.class ); StubLocalDatabase localDatabase = new StubLocalDatabase( 1 ); final ReplayableCommitProcess txListener = new ReplayableCommitProcess( localDatabase, localDatabase ); txListener.commit( newTx1, NULL, EXTERNAL ); txListener.commit( newTx2, NULL, EXTERNAL ); txListener.commit( newTx3, NULL, EXTERNAL ); verify( localDatabase.commitProcess, times( 3 ) ).commit( any( TransactionToApply.class ), any( CommitEvent.class ), any( TransactionApplicationMode.class ) ); }
@Test public void shouldNotCommitTransactionsThatAreAlreadyCommittedLocally() throws Exception { TransactionToApply alreadyCommittedTx1 = mock( TransactionToApply.class ); TransactionToApply alreadyCommittedTx2 = mock( TransactionToApply.class ); TransactionToApply newTx = mock( TransactionToApply.class ); StubLocalDatabase localDatabase = new StubLocalDatabase( 3 ); final ReplayableCommitProcess txListener = new ReplayableCommitProcess( localDatabase, localDatabase ); txListener.commit( alreadyCommittedTx1, NULL, EXTERNAL ); txListener.commit( alreadyCommittedTx2, NULL, EXTERNAL ); txListener.commit( newTx, NULL, EXTERNAL ); verify( localDatabase.commitProcess, times( 1 ) ).commit( eq( newTx ), any( CommitEvent.class ), any( TransactionApplicationMode.class ) ); verifyNoMoreInteractions( localDatabase.commitProcess ); }