### Question:
TxValidatorNonceRangeValidator implements  TxValidatorStep { @Override public boolean validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx) { BigInteger nonce = tx.getNonceAsInteger(); BigInteger stateNonce = state == null ? BigInteger.ZERO : state.getNonce(); BigInteger maxNumberOfTxsPerAddress = BigInteger.valueOf(4); return stateNonce.compareTo(nonce) <= 0 && stateNonce.add(maxNumberOfTxsPerAddress).compareTo(nonce) >= 0; }  @Override boolean validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx);  }### Answer:
@Test public void nonceInRange() { Transaction tx1 = Mockito.mock(Transaction.class); Transaction tx2 = Mockito.mock(Transaction.class); AccountState as = Mockito.mock(AccountState.class); Mockito.when(tx1.getNonceAsInteger()).thenReturn(BigInteger.valueOf(0)); Mockito.when(tx2.getNonceAsInteger()).thenReturn(BigInteger.valueOf(3)); Mockito.when(as.getNonce()).thenReturn(BigInteger.valueOf(0)); TxValidatorNonceRangeValidator tvnrv = new TxValidatorNonceRangeValidator(); Assert.assertTrue(tvnrv.validate(tx1, as, null, null, Long.MAX_VALUE, false)); Assert.assertTrue(tvnrv.validate(tx2, as, null, null, Long.MAX_VALUE, false)); }
@Test public void nonceOutOfRange() { Transaction tx1 = Mockito.mock(Transaction.class); Transaction tx2 = Mockito.mock(Transaction.class); AccountState as = Mockito.mock(AccountState.class); Mockito.when(tx1.getNonceAsInteger()).thenReturn(BigInteger.valueOf(0)); Mockito.when(tx2.getNonceAsInteger()).thenReturn(BigInteger.valueOf(6)); Mockito.when(as.getNonce()).thenReturn(BigInteger.valueOf(1)); TxValidatorNonceRangeValidator tvnrv = new TxValidatorNonceRangeValidator(); Assert.assertFalse(tvnrv.validate(tx1, as, null, null, Long.MAX_VALUE, false)); Assert.assertFalse(tvnrv.validate(tx2, as, null, null, Long.MAX_VALUE, false)); }