### Question:
CmsPsuAisServiceInternal implements CmsPsuAisService { @Override public @NotNull Optional<CmsPsuAuthorisation> getAuthorisationByAuthorisationId(@NotNull String authorisationId, @NotNull String instanceId) { Optional<AuthorisationEntity> optionalAuthorisation = authorisationRepository .findOne(authorisationSpecification.byExternalIdAndInstanceId(authorisationId, instanceId)); if (optionalAuthorisation.isPresent()) { AuthorisationEntity authorisation = optionalAuthorisation.get(); return Optional.of(cmsPsuAuthorisationMapper.mapToCmsPsuAuthorisation(authorisation)); } log.info("Authorisation ID: [{}], Instance ID: [{}]. Get authorisation failed, because authorisation not found", authorisationId, instanceId); return Optional.empty(); }  @Override @Transactional boolean updatePsuDataInConsent(@NotNull PsuIdData psuIdData, @NotNull String authorisationId, @NotNull String instanceId); @Override @Transactional @NotNull Optional<CmsAisConsentResponse> checkRedirectAndGetConsent(@NotNull String redirectId,
                                                                               @NotNull String instanceId); @Override @Transactional @NotNull Optional<CmsAisAccountConsent> getConsent(@NotNull PsuIdData psuIdData, @NotNull String consentId, @NotNull String instanceId); @Override @NotNull Optional<CmsPsuAuthorisation> getAuthorisationByAuthorisationId(@NotNull String authorisationId, @NotNull String instanceId); @Override @Transactional boolean updateAuthorisationStatus(@NotNull PsuIdData psuIdData, @NotNull String consentId,
                                             @NotNull String authorisationId, @NotNull ScaStatus status,
                                             @NotNull String instanceId, AuthenticationDataHolder authenticationDataHolder); @Override @Transactional(rollbackFor = WrongChecksumException.class) boolean confirmConsent(@NotNull String consentId, @NotNull String instanceId); @Override @Transactional(rollbackFor = WrongChecksumException.class) boolean rejectConsent(@NotNull String consentId, @NotNull String instanceId); @Override @NotNull List<CmsAisAccountConsent> getConsentsForPsu(@NotNull PsuIdData psuIdData, @NotNull String instanceId); @Override @Transactional(rollbackFor = WrongChecksumException.class) boolean revokeConsent(@NotNull String consentId, @NotNull String instanceId); @Override @Transactional(rollbackFor = WrongChecksumException.class) boolean authorisePartiallyConsent(@NotNull String consentId, @NotNull String instanceId); @Override @Transactional boolean updateAccountAccessInConsent(@NotNull String consentId, @NotNull CmsAisConsentAccessRequest accountAccessRequest, @NotNull String instanceId); @Override Optional<List<CmsAisPsuDataAuthorisation>> getPsuDataAuthorisations(@NotNull String consentId, @NotNull String instanceId);  }### Answer:
@Test void getAuthorisationByAuthorisationId_success() { when(authorisationRepository.findOne(any(Specification.class))) .thenReturn(Optional.ofNullable(authorisationEntity)); when(authorisationSpecification.byExternalIdAndInstanceId(eq(AUTHORISATION_ID), eq(DEFAULT_SERVICE_INSTANCE_ID))) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(cmsPsuAuthorisationMapper.mapToCmsPsuAuthorisation(authorisationEntity)) .thenReturn(new CmsPsuAuthorisation()); Optional<CmsPsuAuthorisation> cmsPsuAuthorisation = cmsPsuAisService.getAuthorisationByAuthorisationId(AUTHORISATION_ID, DEFAULT_SERVICE_INSTANCE_ID); assertTrue(cmsPsuAuthorisation.isPresent()); }
@Test void getAuthorisationByAuthorisationId_no_authorisation() { when(authorisationRepository.findOne(any(Specification.class))) .thenReturn(Optional.empty()); when(authorisationSpecification.byExternalIdAndInstanceId(eq(AUTHORISATION_ID), eq(DEFAULT_SERVICE_INSTANCE_ID))) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); Optional<CmsPsuAuthorisation> cmsPsuAuthorisation = cmsPsuAisService.getAuthorisationByAuthorisationId(AUTHORISATION_ID, DEFAULT_SERVICE_INSTANCE_ID); assertFalse(cmsPsuAuthorisation.isPresent()); }