### Question:
PiisConsentServiceInternal implements PiisConsentService { @Override @Transactional public CmsResponse<List<CmsConsent>> getPiisConsentListByAccountIdentifier(@Nullable Currency currency, AccountReferenceSelector accountReferenceSelector) { Specification<ConsentEntity> specification; specification = currency == null ? piisConsentEntitySpecification.byAccountReferenceSelector(accountReferenceSelector) : piisConsentEntitySpecification.byCurrencyAndAccountReferenceSelector(currency, accountReferenceSelector); List<CmsConsent> consents = consentJpaRepository.findAll(specification).stream() .map( piisConsentLazyMigrationService::migrateIfNeeded ) .map( consentEntity -> cmsConsentMapper.mapToCmsConsent(consentEntity, Collections.emptyList(), Collections.emptyMap()) ) .collect(Collectors.toList()); return CmsResponse.<List<CmsConsent>>builder() .payload(consents) .build(); }  @Override @Transactional CmsResponse<List<CmsConsent>> getPiisConsentListByAccountIdentifier(@Nullable Currency currency, AccountReferenceSelector accountReferenceSelector);  }### Answer:
@Test void getPiisConsentListByAccountIdentifier() { when(piisConsentEntitySpecification.byCurrencyAndAccountReferenceSelector(CURRENCY, SELECTOR_IBAN)) .thenReturn(SPECIFICATION_IBAN); ConsentEntity validConsentEntity = buildConsentEntity(); when(consentJpaRepository.findAll(SPECIFICATION_IBAN)) .thenReturn(Collections.singletonList(validConsentEntity)); CmsConsent validConsent = buildCmsConsent(); when(cmsConsentMapper.mapToCmsConsent(validConsentEntity, Collections.emptyList(), Collections.emptyMap())) .thenReturn(validConsent); when(piisConsentLazyMigrationService.migrateIfNeeded(validConsentEntity)) .thenReturn(validConsentEntity); CmsConsent expected = buildCmsConsent(); CmsResponse<List<CmsConsent>> piisConsentsResponse = piisConsentServiceInternal.getPiisConsentListByAccountIdentifier(CURRENCY, new AccountReferenceSelector(AccountReferenceType.IBAN, IBAN)); assertTrue(piisConsentsResponse.isSuccessful()); List<CmsConsent> piisConsents = piisConsentsResponse.getPayload(); assertFalse(piisConsents.isEmpty()); assertEquals(expected, piisConsents.get(0)); }
@Test void getPiisConsentListByAccountIdentifier_noCurrency() { when(piisConsentEntitySpecification.byAccountReferenceSelector(SELECTOR_IBAN)) .thenReturn(SPECIFICATION_IBAN); ConsentEntity validConsentEntity = buildConsentEntity(); when(consentJpaRepository.findAll(SPECIFICATION_IBAN)) .thenReturn(Collections.singletonList(validConsentEntity)); CmsConsent validConsent = buildCmsConsent(); when(cmsConsentMapper.mapToCmsConsent(validConsentEntity, Collections.emptyList(), Collections.emptyMap())) .thenReturn(validConsent); when(piisConsentLazyMigrationService.migrateIfNeeded(validConsentEntity)) .thenReturn(validConsentEntity); CmsConsent expected = buildCmsConsent(); CmsResponse<List<CmsConsent>> piisConsentsResponse = piisConsentServiceInternal.getPiisConsentListByAccountIdentifier(null, new AccountReferenceSelector(AccountReferenceType.IBAN, IBAN)); assertTrue(piisConsentsResponse.isSuccessful()); List<CmsConsent> piisConsents = piisConsentsResponse.getPayload(); assertFalse(piisConsents.isEmpty()); assertEquals(expected, piisConsents.get(0)); }
@Test void getPiisConsentListByAccountIdentifier_wrongIban() { CmsResponse<List<CmsConsent>> piisConsentsResponse = piisConsentServiceInternal.getPiisConsentListByAccountIdentifier(CURRENCY, new AccountReferenceSelector(AccountReferenceType.IBAN, WRONG_IBAN)); assertTrue(piisConsentsResponse.getPayload().isEmpty()); }