### Question:
PaymentAspectService extends BaseAspectService<PaymentController> { public ResponseObject<PaymentInitiationResponse> createPaymentAspect(ResponseObject<PaymentInitiationResponse> result, PaymentInitiationParameters requestParameters) { if (!result.hasError()) { PaymentInitiationResponse body = result.getBody(); boolean explicitPreferred = requestParameters.isTppExplicitAuthorisationPreferred(); boolean explicitMethod = authorisationMethodDecider.isExplicitMethod(explicitPreferred, body.isMultilevelScaRequired()); boolean signingBasketModeActive = authorisationMethodDecider.isSigningBasketModeActive(explicitPreferred); body.setLinks(new PaymentInitiationLinks(getHttpUrl(), scaApproachResolver, redirectLinkBuilder, redirectIdService, requestParameters, body, explicitMethod, signingBasketModeActive, getScaRedirectFlow(), isAuthorisationConfirmationRequestMandated(), requestProviderService.getInstanceId())); } return result; } @Autowired  PaymentAspectService(ScaApproachResolver scaApproachResolver,
                                AuthorisationMethodDecider authorisationMethodDecider, RedirectLinkBuilder redirectLinkBuilder,
                                AspspProfileServiceWrapper aspspProfileServiceWrapper, RedirectIdService redirectIdService,
                                RequestProviderService requestProviderService); ResponseObject<PaymentInitiationResponse> createPaymentAspect(ResponseObject<PaymentInitiationResponse> result, PaymentInitiationParameters requestParameters);  }### Answer:
@Test void createPaymentAspect_success() { AspspSettings aspspSettings = new JsonReader().getObjectFromFile("json/aspect/aspsp-settings.json", AspspSettings.class); when(aspspProfileServiceWrapper.isForceXs2aBaseLinksUrl()).thenReturn(aspspSettings.getCommon().isForceXs2aBaseLinksUrl()); when(aspspProfileServiceWrapper.getXs2aBaseLinksUrl()).thenReturn(aspspSettings.getCommon().getXs2aBaseLinksUrl()); when(requestParameters.isTppExplicitAuthorisationPreferred()).thenReturn(true); when(paymentInitiationResponse.isMultilevelScaRequired()).thenReturn(true); when(authorisationMethodDecider.isExplicitMethod(true, true)).thenReturn(true); when(paymentInitiationResponse.getTransactionStatus()).thenReturn(TransactionStatus.RJCT); responseObject = ResponseObject.<PaymentInitiationResponse>builder() .body(paymentInitiationResponse) .build(); ResponseObject actualResponse = service.createPaymentAspect(responseObject, requestParameters); verify(paymentInitiationResponse, times(1)).setLinks(any(PaymentInitiationLinks.class)); assertFalse(actualResponse.hasError()); }
@Test void createPisAuthorizationAspect_withError_shouldAddTextErrorMessage() { responseObject = ResponseObject.builder() .fail(AIS_400, of(CONSENT_UNKNOWN_400)) .build(); ResponseObject actualResponse = service.createPaymentAspect(responseObject, requestParameters); assertTrue(actualResponse.hasError()); assertEquals(CONSENT_UNKNOWN_400, actualResponse.getError().getTppMessage().getMessageErrorCode()); }