@Test
public void decrypt_locksAndUnlocksTheReconnectLockWhenLoginError() throws Exception {

  when(keySet.get(activeKeyUuid))
    .thenReturn(firstActiveKey);
  when(firstActiveKey.decrypt(any(byte[].class), any(byte[].class)))
    .thenThrow(new ProviderException("function 'C_GenerateRandom' returns 0x30"));
  reset(writeLock);
  doThrow(new RuntimeException()).when(encryptionService)
    .reconnect(any(Exception.class));
  try {
    subject.decrypt(new EncryptedValue(activeKeyUuid, "an encrypted value".getBytes(UTF_8), "a nonce".getBytes(UTF_8)));
  } catch (final IllegalBlockSizeException | RuntimeException e) {
    // expected
  }
  verify(readLock, times(2)).lock();
  verify(readLock, times(2)).unlock();
  verify(writeLock, times(1)).lock();
  verify(writeLock, times(1)).unlock();
}