### Question:
ConsentServiceInternal implements ConsentService { @Override public CmsResponse<List<PsuIdData>> getPsuDataByConsentId(String consentId) { Optional<List<PsuIdData>> psuIdDataOptional = getActualAisConsent(consentId) .map(ac -> psuDataMapper.mapToPsuIdDataList(ac.getPsuDataList())); if (psuIdDataOptional.isPresent()) { return CmsResponse.<List<PsuIdData>>builder() .payload(psuIdDataOptional.get()) .build(); } log.info("Consent ID [{}]. Get psu data by consent id failed, because consent not found", consentId); return CmsResponse.<List<PsuIdData>>builder() .error(LOGICAL_ERROR) .build(); }  @Override @Transactional(rollbackFor = WrongChecksumException.class) CmsResponse<CmsCreateConsentResponse> createConsent(CmsConsent cmsConsent); @Override @Transactional CmsResponse<ConsentStatus> getConsentStatusById(String consentId); @Override @Transactional(rollbackFor = WrongChecksumException.class) CmsResponse<Boolean> updateConsentStatusById(String consentId, ConsentStatus status); @Override @Transactional CmsResponse<CmsConsent> getConsentById(String consentId); @Override @Transactional CmsResponse<Boolean> findAndTerminateOldConsentsByNewConsentId(String newConsentId); @Override CmsResponse<List<PsuIdData>> getPsuDataByConsentId(String consentId); @Override @Transactional(rollbackFor = WrongChecksumException.class) CmsResponse<Boolean> updateMultilevelScaRequired(String consentId, boolean multilevelScaRequired);  }### Answer:
@Test void getPsuDataByConsentId_success() { when(consentJpaRepository.findByExternalId(EXTERNAL_CONSENT_ID)) .thenReturn(Optional.ofNullable(consentEntity)); when(psuDataMapper.mapToPsuIdDataList(anyList())) .thenReturn(Collections.singletonList(PSU_ID_DATA)); CmsResponse<List<PsuIdData>> psuDataList = consentServiceInternal.getPsuDataByConsentId(EXTERNAL_CONSENT_ID); assertEquals(PSU_ID_DATA, psuDataList.getPayload().get(0)); }
@Test void getPsuDataByConsentId_noPsuData_shouldReturnLogicalError() { when(consentJpaRepository.findByExternalId(EXTERNAL_CONSENT_ID)) .thenReturn(Optional.empty()); CmsResponse<List<PsuIdData>> actual = consentServiceInternal.getPsuDataByConsentId(EXTERNAL_CONSENT_ID); assertLogicalError(actual); }