### Question:
SecurityDataService { public Optional<String> encryptId(String originalId) { String consentKey = RandomStringUtils.random(16, 0, 0, true, true, null, random); String compositeConsentId = concatWithSeparator(originalId, consentKey, cryptoProviderHolder.getDefaultDataProvider().getCryptoProviderId()); byte[] bytesCompositeConsentId = compositeConsentId.getBytes(); Optional<String> encryptedId = cryptoProviderHolder.getDefaultIdProvider() .encryptData(bytesCompositeConsentId, serverKey) .map(EncryptedData::getData) .map(raw -> Base64.getUrlEncoder().encodeToString(raw)) .map(this::addVersionToEncryptedId); if (encryptedId.isEmpty()) { log.info("ID: [{}]. Couldn't encrypt ID", originalId); } return encryptedId; } @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 getEncryptedId_Success() { when(cryptoProviderHolder.getDefaultIdProvider()) .thenReturn(CRYPTO_PROVIDER); when(cryptoProviderHolder.getDefaultDataProvider()) .thenReturn(CRYPTO_PROVIDER); Optional<String> actual = securityDataService.encryptId(CONSENT_ID); assertTrue(actual.isPresent()); String encryptedId = actual.get(); assertTrue(encryptedId.endsWith(SEPARATOR + CRYPTO_PROVIDER_ID)); String[] splitId = decryptAndSplitConsentId(encryptedId); String consentId = splitId[0]; String consentKey = splitId[1]; assertEquals(CONSENT_ID, consentId); assertEquals(CONSENT_KEY_LENGTH, consentKey.length()); }
@Test void getEncryptedId_Failure_EncryptionError() { when(cryptoProviderHolder.getDefaultIdProvider()) .thenReturn(FAILING_CRYPTO_PROVIDER); when(cryptoProviderHolder.getDefaultDataProvider()) .thenReturn(FAILING_CRYPTO_PROVIDER); Optional<String> actual = securityDataService.encryptId(CONSENT_ID); assertFalse(actual.isPresent()); }