@Test
public void usingTwoThread_wontRetryTwice() throws Exception {

  final Object lock = new Object();
  final Thread firstThread = new Thread("first") {
    @SuppressFBWarnings(
      value = "DE_MIGHT_IGNORE",
      justification = "Exception is a no-op in this test"
    )
    @Override
    public void run() {
      try {
        subject.decrypt(new EncryptedValue(activeKeyUuid, "a value 1".getBytes(UTF_8), "nonce".getBytes(UTF_8)));
      } catch (final Exception e) {
        //do nothing
      }
    }
  };
  final Thread secondThread = new Thread("second") {
    @SuppressFBWarnings(
      value = "DE_MIGHT_IGNORE",
      justification = "Exception is a no-op in this test"
    )
    @Override
    public void run() {
      try {
        subject.decrypt(new EncryptedValue(activeKeyUuid, "a value 2".getBytes(UTF_8), "nonce".getBytes(UTF_8)));
      } catch (final Exception e) {
        //do nothing
      }
    }
  };
  subject = new RacingRetryingEncryptionServiceForTest(firstThread, secondThread, lock);
  when(keySet.get(activeKeyUuid))
    .thenReturn(firstActiveKey);
  when(keySet.getActive())
    .thenReturn(firstActiveKey);
  when(encryptionService.isLoggedIn()).thenReturn(true);
  when(firstActiveKey.decrypt(any(byte[].class), any(byte[].class)))
    .thenThrow(new ProviderException("function 'C_GenerateRandom' returns 0x30"));
  when(firstActiveKey.getProvider()).thenReturn(encryptionService);
  firstThread.start();
  firstThread.join();
  secondThread.join();
  verify(keySet, times(1)).reload();
}