### Question:
CmsPsuPiisServiceInternal implements CmsPsuPiisService { @Override public @NotNull List<CmsPiisConsent> getConsentsForPsu(@NotNull PsuIdData psuIdData, @NotNull String instanceId) { return consentJpaRepository.findAll(piisConsentEntitySpecification.byPsuDataAndInstanceId(psuIdData, instanceId)).stream() .filter(con -> isPsuIdDataContentEquals(con, psuIdData)) .map(piisConsentLazyMigrationService::migrateIfNeeded) .map(piisConsentMapper::mapToCmsPiisConsent) .collect(Collectors.toList()); }  @Override @NotNull Optional<CmsPiisConsent> getConsent(@NotNull PsuIdData psuIdData, @NotNull String consentId, @NotNull String instanceId); @Override @NotNull List<CmsPiisConsent> getConsentsForPsu(@NotNull PsuIdData psuIdData, @NotNull String instanceId); @Override @Transactional boolean revokeConsent(@NotNull PsuIdData psuIdData, @NotNull String consentId, @NotNull String instanceId);  }### Answer:
@Test void getConsentsForPsu_success() { when(psuDataMapper.mapToPsuIdData(psuData)).thenReturn(psuIdData); when(piisConsentEntitySpecification.byPsuDataAndInstanceId(psuIdData, DEFAULT_SERVICE_INSTANCE_ID)) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(consentJpaRepository.findAll(any())).thenReturn(Collections.singletonList(piisConsentEntity)); List<CmsPiisConsent> consents = cmsPsuPiisServiceInternal.getConsentsForPsu(psuIdData, DEFAULT_SERVICE_INSTANCE_ID); assertFalse(consents.isEmpty()); assertEquals(1, consents.size()); }
@Test void getConsentsForPsu_success_shouldIgnoreIpAddressDifferenceInPsu() { when(psuDataMapper.mapToPsuIdData(psuData)).thenReturn(psuIdData); PsuIdData psuIdDataWithIp = jsonReader.getObjectFromFile("json/service/psu/piis/psu-data-ip-address.json", PsuIdData.class); when(piisConsentEntitySpecification.byPsuDataAndInstanceId(psuIdDataWithIp, DEFAULT_SERVICE_INSTANCE_ID)) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(consentJpaRepository.findAll(any())).thenReturn(Collections.singletonList(piisConsentEntity)); List<CmsPiisConsent> consents = cmsPsuPiisServiceInternal.getConsentsForPsu(psuIdDataWithIp, DEFAULT_SERVICE_INSTANCE_ID); assertFalse(consents.isEmpty()); assertEquals(1, consents.size()); }
@Test void getConsentsForPsu_fail() { List<CmsPiisConsent> consents = cmsPsuPiisServiceInternal.getConsentsForPsu(psuIdDataNotExist, DEFAULT_SERVICE_INSTANCE_ID); assertTrue(consents.isEmpty()); }