### Question:
CmsPsuPisServiceInternal implements CmsPsuPisService { @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(cmsPsuPisAuthorisationMapper.mapToCmsPsuAuthorisation(authorisation)); } log.info("Authorisation ID: [{}], Instance ID: [{}]. Get authorisation failed, because authorisation not found", authorisationId, instanceId); return Optional.empty(); }  @Override @Transactional boolean updatePsuInPayment(@NotNull PsuIdData psuIdData, @NotNull String authorisationId, @NotNull String instanceId); @Override @Transactional @NotNull Optional<CmsPaymentResponse> checkRedirectAndGetPayment(@NotNull String redirectId,
                                                                            @NotNull String instanceId); @Transactional @Override @NotNull Optional<CmsPayment> getPayment(@NotNull PsuIdData psuIdData, @NotNull String paymentId, @NotNull String instanceId); @Override @Transactional @NotNull Optional<CmsPaymentResponse> checkRedirectAndGetPaymentForCancellation(@NotNull String redirectId,
                                                                                           @NotNull String instanceId); @Override @NotNull Optional<CmsPsuAuthorisation> getAuthorisationByAuthorisationId(@NotNull String authorisationId, @NotNull String instanceId); @Override @Transactional boolean updateAuthorisationStatus(@NotNull PsuIdData psuIdData, @NotNull String paymentId,
                                             @NotNull String authorisationId, @NotNull ScaStatus status,
                                             @NotNull String instanceId, AuthenticationDataHolder authenticationDataHolder); @Override @Transactional boolean updatePaymentStatus(@NotNull String paymentId, @NotNull TransactionStatus status, @NotNull String instanceId); @Override Optional<List<CmsPisPsuDataAuthorisation>> getPsuDataAuthorisations(@NotNull String paymentId, @NotNull String instanceId);  }### Answer:
@Test void getAuthorisationByAuthorisationId_Success(){ when(authorisationSpecification.byExternalIdAndInstanceId(AUTHORISATION_ID, DEFAULT_SERVICE_INSTANCE_ID)) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); AuthorisationEntity authorisationEntity = buildPisAuthorisation(); when(authorisationRepository.findOne(any(Specification.class))).thenReturn(Optional.of(authorisationEntity)); when(cmsPsuAuthorisationMapper.mapToCmsPsuAuthorisation(authorisationEntity)).thenReturn(buildCmsPsuAuthorisation()); Optional<CmsPsuAuthorisation> cmsPsuAuthorisationOptional = cmsPsuPisServiceInternal.getAuthorisationByAuthorisationId(AUTHORISATION_ID, DEFAULT_SERVICE_INSTANCE_ID); assertTrue(cmsPsuAuthorisationOptional.isPresent()); assertEquals(cmsPsuAuthorisationOptional.get(), buildCmsPsuAuthorisation()); }
@Test void getAuthorisationbyAuthorisationId_authorisationNotFound(){ when(authorisationSpecification.byExternalIdAndInstanceId(AUTHORISATION_ID, DEFAULT_SERVICE_INSTANCE_ID)) .thenReturn(((root, criteriaQuery, criteriaBuilder) -> null)); when(authorisationRepository.findOne(any(Specification.class))).thenReturn(Optional.empty()); Optional<CmsPsuAuthorisation> cmsPsuAuthorisationOptional = cmsPsuPisServiceInternal.getAuthorisationByAuthorisationId(AUTHORISATION_ID, DEFAULT_SERVICE_INSTANCE_ID); assertFalse(cmsPsuAuthorisationOptional.isPresent()); }