### Question:
CmsPsuConfirmationOfFundsServiceInternal implements CmsPsuConfirmationOfFundsService { @Override @Transactional public @NotNull Optional<CmsConfirmationOfFundsConsent> getConsent(@NotNull PsuIdData psuIdData, @NotNull String consentId, @NotNull String instanceId) { return consentJpaRepository.findOne(confirmationOfFundsConsentSpecification.byConsentIdAndInstanceId(consentId, instanceId)) .map(this::mapToCmsConsentWithAuthorisations); }  @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 getConsent() { when(confirmationOfFundsConsentSpecification.byConsentIdAndInstanceId(CONSENT_ID, INSTANCE_ID)) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(consentJpaRepository.findOne(any(Specification.class))) .thenReturn(Optional.of(consentEntity)); List<AuthorisationEntity> authorisations = Collections.singletonList(authorisationEntity); when(consentAuthorisationService.getAuthorisationsByParentExternalId(CONSENT_ID)) .thenReturn(authorisations); Optional<CmsConfirmationOfFundsConsent> actual = cmsPsuConfirmationOfFundsServiceInternal.getConsent(psuIdData, CONSENT_ID, INSTANCE_ID); assertTrue(actual.isPresent()); CmsConfirmationOfFundsConsent expected = jsonReader.getObjectFromFile("json/service/psu/piis/confirmation-of-funds-consent.json", CmsConfirmationOfFundsConsent.class); expected.setCreationTimestamp(actual.get().getCreationTimestamp()); assertEquals(expected, actual.get()); }
@Test void getConsent_consentIsNotFound() { when(confirmationOfFundsConsentSpecification.byConsentIdAndInstanceId(CONSENT_ID, INSTANCE_ID)) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(consentJpaRepository.findOne(any(Specification.class))) .thenReturn(Optional.empty()); Optional<CmsConfirmationOfFundsConsent> actual = cmsPsuConfirmationOfFundsServiceInternal.getConsent(psuIdData, CONSENT_ID, INSTANCE_ID); assertTrue(actual.isEmpty()); verify(consentAuthorisationService, never()).getAuthorisationsByParentExternalId(anyString()); }