### Question:
CmsAspspPiisServiceInternal implements CmsAspspPiisService { @Override @Transactional public @NotNull List<CmsPiisConsent> getConsentsForPsu(@NotNull PsuIdData psuIdData, @NotNull String instanceId) { if (psuIdData.isEmpty()) { return Collections.emptyList(); } return consentJpaRepository.findAll(piisConsentEntitySpecification.byPsuDataAndInstanceId(psuIdData, instanceId)) .stream() .map(piisConsentLazyMigrationService::migrateIfNeeded) .map(piisConsentMapper::mapToCmsPiisConsent) .collect(Collectors.toList()); }  @Override @Transactional Optional<String> createConsent(@NotNull PsuIdData psuIdData, @NotNull CreatePiisConsentRequest request, @NotNull String instanceId); @Override @Transactional @NotNull List<CmsPiisConsent> getConsentsForPsu(@NotNull PsuIdData psuIdData, @NotNull String instanceId); @Override @Transactional boolean terminateConsent(@NotNull String consentId, @NotNull String instanceId);  }### Answer:
@Test void getConsentsForPsu_Success() { PsuIdData psuIdData = buildPsuIdData(PSU_ID); when(piisConsentEntitySpecification.byPsuDataAndInstanceId(psuIdData, DEFAULT_SERVICE_INSTANCE_ID)).thenReturn((root, criteriaQuery, criteriaBuilder) -> null); List<ConsentEntity> piisConsentEntities = Collections.singletonList(buildPiisConsentEntity()); when(consentJpaRepository.findAll(any(Specification.class))) .thenReturn(piisConsentEntities); when(piisConsentLazyMigrationService.migrateIfNeeded(buildPiisConsentEntity())).thenReturn(buildPiisConsentEntity()); when(piisConsentMapper.mapToCmsPiisConsent(buildPiisConsentEntity())).thenReturn(buildCmsPiisConsent()); CmsPiisConsent expected = buildCmsPiisConsent(); List<CmsPiisConsent> actual = cmsAspspPiisServiceInternal.getConsentsForPsu(psuIdData, DEFAULT_SERVICE_INSTANCE_ID); assertFalse(actual.isEmpty()); assertEquals(expected, actual.get(0)); verify(piisConsentEntitySpecification, times(1)) .byPsuDataAndInstanceId(psuIdData, DEFAULT_SERVICE_INSTANCE_ID); }
@Test void getConsentsForPsu_Failure_WrongPsuId() { PsuIdData psuIdData = buildPsuIdData(PSU_ID_WRONG); List<CmsPiisConsent> actual = cmsAspspPiisServiceInternal.getConsentsForPsu(psuIdData, DEFAULT_SERVICE_INSTANCE_ID); assertTrue(actual.isEmpty()); verify(piisConsentEntitySpecification, times(1)) .byPsuDataAndInstanceId(psuIdData, DEFAULT_SERVICE_INSTANCE_ID); }
@Test void getConsentsForPsu_withEmptyPsuId_shouldReturnEmpty() { PsuIdData emptyPsuIdData = buildPsuIdData(null); List<CmsPiisConsent> actual = cmsAspspPiisServiceInternal.getConsentsForPsu(emptyPsuIdData, DEFAULT_SERVICE_INSTANCE_ID); assertTrue(actual.isEmpty()); verify(consentJpaRepository, never()).findAll(any()); }