@Test
public void shouldRequestFailEvenOnNonceRefresh() throws Exception {

  // given
  final AccountOperation mockAccountOperation = mock(AccountOperation.class);
  when(mockAccountOperation.getState(any(AccountAddress.class)))
      .thenReturn(AccountState.newBuilder().nonce(1L).build());
  final AergoClient mockClient = mock(AergoClient.class);
  when(mockClient.getAccountOperation()).thenReturn(mockAccountOperation);
  final TryCountAndInterval tryCountAndInterval = TryCountAndInterval.of(3, Time.of(100L));
  final TxRequester txRequester = new NonceRefreshingTxRequester(tryCountAndInterval,
      new SimpleNonceProvider());
  final AergoKey signer = new AergoKeyGenerator().create();
  final CommitException expected = new CommitException(CommitStatus.TX_HAS_SAME_NONCE, "Error");
  final TxRequestFunction requestFunction = new TxRequestFunction() {
    @Override
    public TxHash apply(Signer signer, Long aLong) {
      throw expected;
    }
  };
  try {
    txRequester.request(mockClient, signer, requestFunction);
    fail("Should throw CommitException");
  } catch (Exception actual) {
    // then
    assertEquals(expected, actual);
  }
}