### Question:
CmsConsentAuthorisationServiceInternal { public Optional<AuthorisationEntity> getAuthorisationByRedirectId(String redirectId, String instanceId) throws RedirectUrlIsExpiredException { Optional<AuthorisationEntity> authorisation = authorisationRepository.findOne(authorisationSpecification.byExternalIdAndInstanceId(redirectId, instanceId)); if (authorisation.isPresent() && !authorisation.get().isRedirectUrlNotExpired()) { log.info("Authorisation ID [{}], Instance ID: [{}]. Check redirect URL and get consent failed, because authorisation is expired", redirectId, instanceId); authorisation.get().setScaStatus(ScaStatus.FAILED); throw new RedirectUrlIsExpiredException(authorisation.get().getTppNokRedirectUri()); } return authorisation; }  Optional<AuthorisationEntity> getAuthorisationByAuthorisationId(@NotNull String authorisationId, @NotNull String instanceId); Optional<AuthorisationEntity> getAuthorisationByRedirectId(String redirectId, String instanceId); boolean updateScaStatusAndAuthenticationData(@NotNull ScaStatus status, AuthorisationEntity authorisation, AuthenticationDataHolder authenticationDataHolder); List<AuthorisationEntity> getAuthorisationsByParentExternalId(String externalId);  }### Answer:
@Test void getAuthorisationByRedirectId_success() throws RedirectUrlIsExpiredException { authorisationEntity.setRedirectUrlExpirationTimestamp(OffsetDateTime.now().plusDays(1)); when(authorisationSpecification.byExternalIdAndInstanceId(AUTHORISATION_ID, INSTANCE_ID)) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(authorisationRepository.findOne(any(Specification.class))) .thenReturn(Optional.of(authorisationEntity)); Optional<AuthorisationEntity> actual = cmsConsentAuthorisationServiceInternal.getAuthorisationByRedirectId(AUTHORISATION_ID, INSTANCE_ID); assertTrue(actual.isPresent()); assertEquals(authorisationEntity, actual.get()); }
@Test void getAuthorisationByRedirectId_redirectUrlIsExpired() { authorisationEntity.setRedirectUrlExpirationTimestamp(OffsetDateTime.now().minusDays(1)); when(authorisationSpecification.byExternalIdAndInstanceId(AUTHORISATION_ID, INSTANCE_ID)) .thenReturn((root, criteriaQuery, criteriaBuilder) -> null); when(authorisationRepository.findOne(any(Specification.class))) .thenReturn(Optional.of(authorisationEntity)); assertThrows(RedirectUrlIsExpiredException.class, () -> cmsConsentAuthorisationServiceInternal.getAuthorisationByRedirectId(AUTHORISATION_ID, INSTANCE_ID)); assertEquals(ScaStatus.FAILED, authorisationEntity.getScaStatus()); }