### Question:
UnconfirmedTransactionDetector { public static Optional<DateTime> calculateReplayDate(Wallet wallet, DateTime compareDate) { Preconditions.checkNotNull(wallet); Preconditions.checkNotNull(compareDate); Map<Sha256Hash, Transaction> pending = wallet.getTransactionPool(WalletTransaction.Pool.PENDING); Optional<DateTime> replayDate = Optional.absent(); for (Transaction loopTransaction : pending.values()) { DateTime loopTransactionTime = new DateTime(loopTransaction.getUpdateTime()); if (compareDate.minus(LOWER_LIMIT_OF_TIME_WINDOW).isAfter(loopTransactionTime) && compareDate.isBefore(loopTransactionTime.plus(UPPER_LIMIT_OF_TIME_WINDOW))) { if (replayDate.isPresent()) { if (replayDate.get().isAfter(loopTransactionTime)) { replayDate = Optional.of(loopTransactionTime); } } else { replayDate = Optional.of(loopTransactionTime); } } } log.debug("Calculated replay date for unconfirmed transaction is {}", replayDate); return replayDate; } private  UnconfirmedTransactionDetector(); static Optional<DateTime> calculateReplayDate(Wallet wallet, DateTime compareDate); static final Hours LOWER_LIMIT_OF_TIME_WINDOW; static final Days UPPER_LIMIT_OF_TIME_WINDOW; }### Answer:
@Test public void testWindowOfInterest() throws Exception { File applicationDirectory = SecureFiles.createTemporaryDirectory(); WalletManager walletManager = WalletManager.INSTANCE; BackupManager.INSTANCE.initialise(applicationDirectory, Optional.<File>absent()); byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Bip39SeedPhraseGenerator.split(WalletIdTest.SEED_PHRASE_1)); SeedPhraseGenerator seedGenerator = new Bip39SeedPhraseGenerator(); byte[] seed = seedGenerator.convertToSeed(Bip39SeedPhraseGenerator.split(WalletIdTest.SEED_PHRASE_1)); long nowInSeconds = Dates.nowInSeconds(); WalletSummary walletSummary = walletManager .getOrCreateMBHDSoftWalletSummaryFromEntropy( applicationDirectory, entropy, seed, nowInSeconds, "credentials", "Example", "Example", false); assertThat(walletSummary).isNotNull(); assertThat(walletSummary.getWallet()).isNotNull(); wallet = walletSummary.getWallet(); myKey = wallet.currentReceiveKey(); myAddress = myKey.toAddress(mainNet); DateTime now = Dates.nowUtc(); Optional<DateTime> replayDate = UnconfirmedTransactionDetector.calculateReplayDate(wallet, now); assertThat(!replayDate.isPresent()).isTrue(); Transaction unconfirmedTransaction = sendMoneyToWallet(); assertThat(unconfirmedTransaction).isNotNull(); replayDate = UnconfirmedTransactionDetector.calculateReplayDate(wallet, now); assertThat(!replayDate.isPresent()).isTrue(); replayDate = UnconfirmedTransactionDetector.calculateReplayDate(wallet, now.plus(Hours.FOUR).plus(Minutes.ONE)); assertThat(replayDate.isPresent()).isTrue(); assertThat(replayDate.get().toDate()).isEqualTo(unconfirmedTransaction.getUpdateTime()); replayDate = UnconfirmedTransactionDetector.calculateReplayDate(wallet, now.plus(Days.FOUR).minus(Minutes.ONE)); assertThat(replayDate.isPresent()).isTrue(); assertThat(replayDate.get().toDate()).isEqualTo(unconfirmedTransaction.getUpdateTime()); replayDate = UnconfirmedTransactionDetector.calculateReplayDate(wallet, now.plus(Days.FOUR).plus(Minutes.ONE)); assertThat(!replayDate.isPresent()).isTrue(); }