@Test
public void retrieveSecrets() throws Exception {

    //GIVEN
    final DbEncryptionKeyReference keyReference = new DbEncryptionKeyReference();
    final DbEncryptedSecret secret = new DbEncryptedSecret();
    secret.setSecretType(SecretType.E_METER_MASTER_KEY);
    secret.setEncryptionKeyReference(keyReference);
    final Secret decryptedSecret = new Secret("secret".getBytes());
    //WHEN
    when(this.secretRepository.findIdOfValidMostRecent(any(), any(), any())).thenReturn(1L);
    when(this.secretRepository.findById(any())).thenReturn(Optional.of(secret));
    when(this.encryptionDelegate.decrypt(any(), any())).thenReturn(decryptedSecret);
    final List<TypedSecret> typedSecrets = this.service.retrieveSecrets(SOME_DEVICE,
            Arrays.asList(SecretType.E_METER_MASTER_KEY));
    //THEN
    assertThat(typedSecrets).isNotNull();
    assertThat(typedSecrets.size()).isEqualTo(1);
    final TypedSecret typedSecret = typedSecrets.get(0);
    assertThat(typedSecret.getSecret()).isEqualTo(HexUtils.toHexString("secret".getBytes()));
    assertThat(typedSecret.getSecretType()).isEqualTo(SecretType.E_METER_MASTER_KEY);
}