### Question:
AccountTransactionOrder { public Iterable<Transaction> transactionsToProcess( final Transaction nextTransactionInPriorityOrder) { deferredTransactions.add(nextTransactionInPriorityOrder); final List<Transaction> transactionsToApply = new ArrayList<>(); while (!deferredTransactions.isEmpty() && !transactionsForSender.isEmpty() && deferredTransactions.first().equals(transactionsForSender.first())) { final Transaction transaction = deferredTransactions.first(); transactionsToApply.add(transaction); deferredTransactions.remove(transaction); transactionsForSender.remove(transaction); } return transactionsToApply; } AccountTransactionOrder(final Stream<Transaction> senderTransactions); Iterable<Transaction> transactionsToProcess(
      final Transaction nextTransactionInPriorityOrder);  }### Answer:
@Test public void shouldProcessATransactionImmediatelyIfItsTheLowestNonce() { assertThat(accountTransactionOrder.transactionsToProcess(transaction1)) .containsExactly(transaction1); }
@Test public void shouldDeferProcessingATransactionIfItIsNotTheLowestNonce() { assertThat(accountTransactionOrder.transactionsToProcess(transaction2)).isEmpty(); }
@Test public void shouldProcessDeferredTransactionsAfterPrerequisiteIsProcessed() { assertThat(accountTransactionOrder.transactionsToProcess(transaction2)).isEmpty(); assertThat(accountTransactionOrder.transactionsToProcess(transaction3)).isEmpty(); assertThat(accountTransactionOrder.transactionsToProcess(transaction1)) .containsExactly(transaction1, transaction2, transaction3); }
@Test public void shouldNotProcessDeferredTransactionsThatAreNotYetDue() { assertThat(accountTransactionOrder.transactionsToProcess(transaction2)).isEmpty(); assertThat(accountTransactionOrder.transactionsToProcess(transaction4)).isEmpty(); assertThat(accountTransactionOrder.transactionsToProcess(transaction1)) .containsExactly(transaction1, transaction2); assertThat(accountTransactionOrder.transactionsToProcess(transaction3)) .containsExactly(transaction3, transaction4); }