### Question:
ConsentAuthorisationService { public ResponseObject<Xs2aAuthorisationSubResources> getConsentInitiationAuthorisations(String consentId) { xs2aEventService.recordConsentTppRequest(consentId, EventType.GET_CONSENT_AUTHORISATION_REQUEST_RECEIVED); Optional<AisConsent> aisConsentOptional = aisConsentService.getAccountConsentById(consentId); if (aisConsentOptional.isEmpty()) { log.info("Consent-ID: [{}]. Get consent initiation authorisations failed: consent not found by id", consentId); return ResponseObject.<Xs2aAuthorisationSubResources>builder() .fail(AIS_403, of(CONSENT_UNKNOWN_403)).build(); } AisConsent aisConsent = aisConsentOptional.get(); ValidationResult validationResult = consentValidationService.validateConsentAuthorisationOnGettingById(aisConsent); if (validationResult.isNotValid()) { log.info("Consent-ID: [{}]. Get consent authorisations - validation failed: {}", consentId, validationResult.getMessageError()); return ResponseObject.<Xs2aAuthorisationSubResources>builder() .fail(validationResult.getMessageError()) .build(); } loggingContextService.storeConsentStatus(aisConsent.getConsentStatus()); return getAuthorisationSubResources(consentId) .map(resp -> ResponseObject.<Xs2aAuthorisationSubResources>builder().body(resp).build()) .orElseGet(() -> { log.info("Consent-ID: [{}]. Get consent initiation authorisations failed: authorisation not found at CMS by consent id", consentId); return ResponseObject.<Xs2aAuthorisationSubResources>builder() .fail(AIS_404, of(RESOURCE_UNKNOWN_404)) .build(); }); }  ResponseObject<AuthorisationResponse> createAisAuthorisation(PsuIdData psuData, String consentId, String password); ResponseObject<Xs2aAuthorisationSubResources> getConsentInitiationAuthorisations(String consentId); ResponseObject<ConsentScaStatus> getConsentAuthorisationScaStatus(String consentId, String authorisationId); ResponseObject<UpdateConsentPsuDataResponse> updateConsentPsuData(UpdateConsentPsuDataReq updatePsuData);  }### Answer:
@Test void getConsentInitiationAuthorisations_withInvalidConsent_shouldReturnValidationError() { when(aisConsentService.getAccountConsentById(CONSENT_ID)).thenReturn(Optional.of(aisConsent)); when(consentValidationService.validateConsentAuthorisationOnGettingById(aisConsent)) .thenReturn(ValidationResult.invalid(CONSENT_INVALID_401_ERROR)); ResponseObject<Xs2aAuthorisationSubResources> actualResponse = service.getConsentInitiationAuthorisations(CONSENT_ID); verify(aisConsentService, times(1)).getAccountConsentById(CONSENT_ID); verify(consentValidationService, times(1)).validateConsentAuthorisationOnGettingById(aisConsent); assertValidationError(actualResponse); }
@Test void getConsentInitiationAuthorisations_withUnknownConsent_shouldReturnConsentUnknownError() { when(aisConsentService.getAccountConsentById(WRONG_CONSENT_ID)).thenReturn(Optional.empty()); ResponseObject<Xs2aAuthorisationSubResources> response = service.getConsentInitiationAuthorisations(WRONG_CONSENT_ID); assertThat(response.getError()).isEqualTo(CONSENT_UNKNOWN_403_ERROR); }
@Test void getConsentInitiationAuthorisations_shouldRecordStatusInLoggingContext() { when(aisConsentService.getAccountConsentById(CONSENT_ID)).thenReturn(Optional.of(aisConsent)); when(consentValidationService.validateConsentAuthorisationOnGettingById(aisConsent)) .thenReturn(ValidationResult.valid()); service.getConsentInitiationAuthorisations(CONSENT_ID); ArgumentCaptor<ConsentStatus> consentStatusArgumentCaptor = ArgumentCaptor.forClass(ConsentStatus.class); verify(loggingContextService).storeConsentStatus(consentStatusArgumentCaptor.capture()); }