@Test
public void encryption_whenReconnectionFails_shouldNotReloadTheKeySet()
  throws Exception {

  final EncryptedValue expectedEncryption = mock(EncryptedValue.class);
  when(keySet.getActive())
    .thenReturn(firstActiveKey)
    .thenReturn(secondActiveKey);
  when(firstActiveKey.encrypt("fake-plaintext"))
    .thenThrow(new IllegalBlockSizeException("test exception"));
  when(firstActiveKey.getProvider()).thenReturn(encryptionService);
  when(secondActiveKey.encrypt("fake-plaintext"))
    .thenReturn(expectedEncryption);
  when(secondActiveKey.getProvider()).thenReturn(encryptionService);
  when(encryptionService.isLoggedIn()).thenReturn(false);
  assertThatThrownBy(() -> {
    subject.encrypt("fake-plaintext");
  }).isInstanceOf(IllegalBlockSizeException.class);
  verify(encryptionService, times(1))
    .reconnect(any(IllegalBlockSizeException.class));
  verify(keySet, times(0)).reload();
}