@Test
public void retrieveSecrets_decryptionError() {

    //GIVEN
    final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference();
    final DbEncryptedSecret secret = new DbEncryptedSecret();
    secret.setSecretType(SecretType.E_METER_MASTER_KEY);
    secret.setEncryptionKeyReference(keyReference);
    //WHEN
    when(this.secretRepository.findIdOfValidMostRecent(any(), any(), any())).thenReturn(1L);
    when(this.secretRepository.findById(1L)).thenReturn(Optional.of(secret));
    when(this.encryptionDelegate.decrypt(any(), any())).thenThrow(new RuntimeException("Decryption error"));
    //THEN
    assertThatIllegalStateException().isThrownBy(
            () -> this.service.retrieveSecrets("SOME_DEVICE", Arrays.asList(SecretType.E_METER_MASTER_KEY)));
}