### Question:
AspspDataServiceInternal implements AspspDataService { @Override @Transactional public boolean deleteAspspConsentData(@NotNull String externalId) { if (!securityDataService.isConsentIdEncrypted(externalId)) { return deleteAspspConsentDataIfExist(externalId); } return securityDataService.decryptId(externalId) .map(this::deleteAspspConsentDataIfExist) .orElseGet(() -> { log.info("External Consent ID: [{}]. Delete aspsp consent data failed, couldn't decrypt consent id", externalId); return false; }); }  @Override @NotNull Optional<AspspConsentData> readAspspConsentData(@NotNull String externalId); @Override @Transactional boolean updateAspspConsentData(@NotNull AspspConsentData aspspConsentData); @Override @Transactional boolean deleteAspspConsentData(@NotNull String externalId);  }### Answer:
@Test void deleteAspspConsentDataSuccess() { when(aspspConsentDataRepository.existsById(EXTERNAL_CONSENT_ID)).thenReturn(true); boolean deleted = aspspDataServiceInternal.deleteAspspConsentData(EXTERNAL_CONSENT_ID); assertTrue(deleted); }
@Test void deleteAspspConsentDataFail_no_aspspConsentData() { boolean deleted = aspspDataServiceInternal.deleteAspspConsentData(EXTERNAL_CONSENT_ID); assertFalse(deleted); }
@Test void deleteAspspConsentDataFail_no_decrypted_id() { when(securityDataService.decryptId(EXTERNAL_CONSENT_ID)).thenReturn(Optional.of(EXTERNAL_CONSENT_ID)); when(securityDataService.isConsentIdEncrypted(EXTERNAL_CONSENT_ID)).thenReturn(true); when(securityDataService.decryptId(EXTERNAL_CONSENT_ID)).thenReturn(Optional.empty()); boolean deleted = aspspDataServiceInternal.deleteAspspConsentData(EXTERNAL_CONSENT_ID); assertFalse(deleted); }
@Test void deleteAspspConsentDataFail_consentId_not_encrypted() { when(securityDataService.isConsentIdEncrypted(EXTERNAL_CONSENT_ID)).thenReturn(false); boolean deleted = aspspDataServiceInternal.deleteAspspConsentData(EXTERNAL_CONSENT_ID); assertFalse(deleted); }