### Question:
SecurityDataService { public Optional<String> decryptId(String encryptedId) { if (!encryptedId.contains(SEPARATOR)) { log.info("ID: [{}]. Couldn't decrypt, because id does not contain separator [{}]", encryptedId, SEPARATOR); return Optional.empty(); } Optional<String> decryptedId = decryptCompositeId(encryptedId) .map(cmst -> cmst.split(SEPARATOR)[0]); if (decryptedId.isEmpty()) { log.info("ID: [{}]. Couldn't decrypt ID", encryptedId); } return decryptedId; } @Autowired  SecurityDataService(Environment environment, CryptoProviderHolder cryptoProviderHolder); Optional<String> encryptId(String originalId); Optional<String> decryptId(String encryptedId); Optional<EncryptedData> encryptConsentData(String encryptedId, byte[] aspspConsentData); Optional<DecryptedData> decryptConsentData(String encryptedId, byte[] aspspConsentData); boolean isConsentIdEncrypted(String consentId);  }### Answer:
@Test void getConsentId_Success() { when(cryptoProviderHolder.getProviderById(CRYPTO_PROVIDER_ID)).thenReturn(Optional.of(CRYPTO_PROVIDER)); String encrypted = getEncryptedConsentId(CRYPTO_PROVIDER_ID); Optional<String> actual = securityDataService.decryptId(encrypted); assertTrue(actual.isPresent()); assertEquals(CONSENT_ID, actual.get()); }
@Test void getConsentId_Failure_WrongExternalIdFormat() { Optional<String> actual = securityDataService.decryptId(CONSENT_ID); assertFalse(actual.isPresent()); }
@Test void getConsentId_Failure_NonExistingAlgorithm() { String encrypted = getEncryptedConsentId(NON_EXISTING_CRYPT_PROVIDER_ID); when(cryptoProviderHolder.getProviderById(NON_EXISTING_CRYPT_PROVIDER_ID)).thenReturn(Optional.empty()); Optional<String> actual = securityDataService.decryptId(encrypted); assertFalse(actual.isPresent()); }
@Test void getConsentId_Failure_DecryptionError() { String encrypted = getEncryptedConsentId(FAILING_CRYPTO_PROVIDER_ID); when(cryptoProviderHolder.getProviderById(FAILING_CRYPTO_PROVIDER_ID)).thenReturn(Optional.of(FAILING_CRYPTO_PROVIDER)); Optional<String> actual = securityDataService.decryptId(encrypted); assertFalse(actual.isPresent()); }