### Question:
PendingTransactions { public OptionalLong getNextNonceForSender(final Address sender) { final TransactionsForSenderInfo transactionsForSenderInfo = transactionsBySender.get(sender); if (transactionsForSenderInfo == null || transactionsForSenderInfo.getTransactionsInfos().isEmpty()) { return OptionalLong.empty(); } else { final OptionalLong maybeNextGap = transactionsForSenderInfo.maybeNextGap(); return maybeNextGap.isEmpty() ? OptionalLong.of(transactionsForSenderInfo.getTransactionsInfos().lastKey() + 1) : maybeNextGap; } } PendingTransactions(
      final int maxTransactionRetentionHours,
      final int maxPendingTransactions,
      final int maxPooledTransactionHashes,
      final Clock clock,
      final MetricsSystem metricsSystem,
      final Supplier<BlockHeader> chainHeadHeaderSupplier,
      final Optional<EIP1559> eip1559,
      final Percentage priceBump); void evictOldTransactions(); boolean addRemoteTransaction(final Transaction transaction); @VisibleForTesting TransactionAddedStatus addLocalTransaction(final Transaction transaction); void selectTransactions(final TransactionSelector selector); long maxSize(); int size(); boolean containsTransaction(final Hash transactionHash); Optional<Transaction> getTransactionByHash(final Hash transactionHash); Set<TransactionInfo> getTransactionInfo(); OptionalLong getNextNonceForSender(final Address sender); void tryEvictTransactionHash(final Hash hash);  }### Answer:
@Test public void shouldReturnEmptyOptionalAsMaximumNonceWhenNoTransactionsPresent() { assertThat(transactions.getNextNonceForSender(SENDER1)).isEmpty(); }
@Test public void assertThatCorrectNonceIsReturned() { assertThat(transactions.getNextNonceForSender(transaction1.getSender())).isEmpty(); addLocalTransactions(1, 2, 4, 5); assertThat(transactions.getNextNonceForSender(transaction1.getSender())) .isPresent() .hasValue(3); addLocalTransactions(3); assertThat(transactions.getNextNonceForSender(transaction1.getSender())) .isPresent() .hasValue(6); addLocalTransactions(6, 10); assertThat(transactions.getNextNonceForSender(transaction1.getSender())) .isPresent() .hasValue(7); }