### Question:
ResponsePacker { public <T> Response<T> packTransactionStreamResponse( RequestContext context, T response ) { final long toStartFrom = context.lastAppliedTransaction() + 1; final long toEndAt = transactionIdStore.getLastCommittedTransactionId(); TransactionStream transactions = visitor -> { if ( toStartFrom > BASE_TX_ID && toStartFrom <= toEndAt ) { extractTransactions( toStartFrom, filterVisitor( visitor, toEndAt ) ); } }; return new TransactionStreamResponse<>( response, storeId.get(), transactions, ResourceReleaser.NO_OP ); } ResponsePacker( LogicalTransactionStore transactionStore, TransactionIdStore transactionIdStore,
                           Supplier<StoreId> storeId ); Response<T> packTransactionStreamResponse( RequestContext context, T response ); Response<T> packTransactionObligationResponse( RequestContext context, T response ); Response<T> packTransactionObligationResponse( RequestContext context, T response,
                                                              long obligationTxId ); Response<T> packEmptyResponse( T response );  }### Answer:
@Test public void shouldHaveFixedTargetTransactionIdEvenIfLastTransactionIdIsMoving() throws Exception { LogicalTransactionStore transactionStore = mock( LogicalTransactionStore.class ); long lastAppliedTransactionId = 5L; TransactionCursor endlessCursor = new EndlessCursor( lastAppliedTransactionId + 1 ); when( transactionStore.getTransactions( anyLong() ) ).thenReturn( endlessCursor ); final long targetTransactionId = 8L; final TransactionIdStore transactionIdStore = new SimpleTransactionIdStore( targetTransactionId, 0, BASE_TX_COMMIT_TIMESTAMP, 0, 0 ); ResponsePacker packer = new ResponsePacker( transactionStore, transactionIdStore, Suppliers.singleton( StoreIdTestFactory.newStoreIdForCurrentVersion() ) ); Response<Object> response = packer.packTransactionStreamResponse( requestContextStartingAt( 5L ), null ); final AtomicLong nextExpectedVisit = new AtomicLong( lastAppliedTransactionId ); response.accept( new Response.Handler() { @Override public void obligation( long txId ) { fail( "Should not be called" ); } @Override public Visitor<CommittedTransactionRepresentation,Exception> transactions() { return element -> { long txId = element.getCommitEntry().getTxId(); assertThat( txId, lessThanOrEqualTo( targetTransactionId ) ); assertEquals( nextExpectedVisit.incrementAndGet(), txId ); transactionIdStore.setLastCommittedAndClosedTransactionId( transactionIdStore.getLastCommittedTransactionId() + 1, 0, BASE_TX_COMMIT_TIMESTAMP, 3, 4 ); return true; }; } } ); }