### Question:
CmsPsuConfirmationOfFundsServiceInternal implements CmsPsuConfirmationOfFundsService { @Override @Transactional public Optional<CmsConfirmationOfFundsResponse> checkRedirectAndGetConsent(String redirectId, String instanceId) throws RedirectUrlIsExpiredException { Optional<AuthorisationEntity> optionalAuthorisation = consentAuthorisationService.getAuthorisationByRedirectId(redirectId, instanceId); if (optionalAuthorisation.isPresent()) { AuthorisationEntity authorisation = optionalAuthorisation.get(); return createCmsConsentResponseFromAuthorisation(authorisation, redirectId); } log.info("Authorisation ID [{}], Instance ID: [{}]. Check redirect URL and get consent failed, because authorisation not found or has finalised status", redirectId, instanceId); return Optional.empty(); }  @Override @Transactional boolean updateAuthorisationStatus(@NotNull PsuIdData psuIdData, @NotNull String consentId,
                                             @NotNull String authorisationId, @NotNull ScaStatus status,
                                             @NotNull String instanceId, AuthenticationDataHolder authenticationDataHolder); @Override @Transactional boolean updatePsuDataInConsent(@NotNull PsuIdData psuIdData, @NotNull String authorisationId, @NotNull String instanceId); @Override @Transactional @NotNull Optional<CmsConfirmationOfFundsConsent> getConsent(@NotNull PsuIdData psuIdData,
                                                                       @NotNull String consentId,
                                                                       @NotNull String instanceId); @Override @Transactional Optional<CmsConfirmationOfFundsResponse> checkRedirectAndGetConsent(String redirectId, String instanceId); @Override @NotNull Optional<CmsPsuConfirmationOfFundsAuthorisation> getAuthorisationByAuthorisationId(@NotNull String authorisationId, @NotNull String instanceId); @Override @Transactional boolean updateConsentStatus(@NotNull String consentId, @NotNull ConsentStatus status, @NotNull String instanceId);  }### Answer:
@Test void checkRedirectAndGetConsent_authorisationNotFound() throws RedirectUrlIsExpiredException { when(consentAuthorisationService.getAuthorisationByRedirectId(AUTHORISATION_ID, INSTANCE_ID)).thenReturn(Optional.empty()); Optional<CmsConfirmationOfFundsResponse> consentResponseOptional = cmsPsuConfirmationOfFundsServiceInternal.checkRedirectAndGetConsent(AUTHORISATION_ID, INSTANCE_ID); assertTrue(consentResponseOptional.isEmpty()); verify(consentJpaRepository, never()).findByExternalId(anyString()); verify(consentAuthorisationService, never()).getAuthorisationsByParentExternalId(anyString()); }
@Test void checkRedirectAndGetConsent_redirectUrlIsExpired() throws RedirectUrlIsExpiredException { when(consentAuthorisationService.getAuthorisationByRedirectId(AUTHORISATION_ID, INSTANCE_ID)) .thenThrow(new RedirectUrlIsExpiredException(TPP_NOK_REDIRECT_URI)); assertThrows(RedirectUrlIsExpiredException.class, () -> cmsPsuConfirmationOfFundsServiceInternal.checkRedirectAndGetConsent(AUTHORISATION_ID, INSTANCE_ID)); verify(consentJpaRepository, never()).findByExternalId(anyString()); verify(consentAuthorisationService, never()).getAuthorisationsByParentExternalId(anyString()); }