### Question:
AisConsentServiceInternal implements AisConsentService { @Override @Transactional(rollbackFor = WrongChecksumException.class) public CmsResponse<CmsConsent> updateAspspAccountAccess(String consentId, AccountAccess request) throws WrongChecksumException { Optional<ConsentEntity> consentOptional = aisConsentRepository.getActualAisConsent(consentId); if (consentOptional.isEmpty()) { log.info("Consent ID [{}]. Update aspsp account access with response failed, because consent not found", consentId); return CmsResponse.<CmsConsent>builder() .error(LOGICAL_ERROR) .build(); } ConsentEntity consentEntity = consentOptional.get(); AccountAccess requestedAccessWithFilledAccounts = fillAccountsWithAllAccountReferences(request); ConsentEntity updatedConsent = updateConsentAccess(consentEntity, requestedAccessWithFilledAccounts); ConsentEntity savedConsent = aisConsentRepository.verifyAndUpdate(updatedConsent); CmsConsent cmsConsent = mapToCmsConsent(savedConsent); return CmsResponse.<CmsConsent>builder() .payload(cmsConsent) .build(); }  @Override @Transactional(rollbackFor = WrongChecksumException.class) CmsResponse<CmsResponse.VoidResponse> checkConsentAndSaveActionLog(AisConsentActionRequest request); @Override @Transactional(rollbackFor = WrongChecksumException.class) CmsResponse<CmsConsent> updateAspspAccountAccess(String consentId, AccountAccess request);  }### Answer:
@Test void updateAspspAccountAccess() throws WrongChecksumException { ConsentEntity consentEntity = jsonReader.getObjectFromFile("json/service/ais-consent-service/consent-entity.json", ConsentEntity.class); when(aisConsentRepository.getActualAisConsent(CONSENT_ID)).thenReturn(Optional.of(consentEntity)); List<AspspAccountAccess> aspspAccountAccesses = jsonReader.getObjectFromFile("json/service/ais-consent-service/aspsp-account-accesses.json", new TypeReference<>() { }); AccountAccess existingAccountAccess = jsonReader.getObjectFromFile("json/service/ais-consent-service/account-access-existing.json", AccountAccess.class); when(accessMapper.mapAspspAccessesToAccountAccess(aspspAccountAccesses, AdditionalAccountInformationType.DEDICATED_ACCOUNTS, AdditionalAccountInformationType.NONE)).thenReturn(existingAccountAccess); AccountAccess accountAccess = jsonReader.getObjectFromFile("json/service/ais-consent-service/account-access.json", AccountAccess.class); AccountAccess updatedAccountAccess = jsonReader.getObjectFromFile("json/service/ais-consent-service/account-access-updated.json", AccountAccess.class); when(accountAccessUpdater.updateAccountReferencesInAccess(existingAccountAccess, accountAccess)).thenReturn(updatedAccountAccess); CmsConsent cmsConsent = jsonReader.getObjectFromFile("json/service/ais-consent-service/cms-consent.json", CmsConsent.class); when(cmsConsentMapper.mapToCmsConsent(eq(consentEntity), anyList(), anyMap())).thenReturn(cmsConsent); when(aisConsentRepository.verifyAndUpdate(consentEntity)).thenReturn(consentEntity); CmsResponse<CmsConsent> response = aisConsentServiceInternal.updateAspspAccountAccess(CONSENT_ID, accountAccess); assertTrue(response.isSuccessful()); verify(accountAccessUpdater).updateAccountReferencesInAccess(existingAccountAccess, accountAccess); }
@Test void updateAspspAccountAccess_noConsent() throws WrongChecksumException { when(aisConsentRepository.getActualAisConsent(CONSENT_ID)).thenReturn(Optional.empty()); AccountAccess accountAccess = jsonReader.getObjectFromFile("json/service/ais-consent-service/account-access.json", AccountAccess.class); CmsResponse<CmsConsent> response = aisConsentServiceInternal.updateAspspAccountAccess(CONSENT_ID, accountAccess); assertTrue(response.hasError()); assertEquals(CmsError.LOGICAL_ERROR, response.getError()); }