### Question:
PaymentCancellationAspectService extends BaseAspectService<PaymentController> { public ResponseObject<CancelPaymentResponse> cancelPayment(ResponseObject<CancelPaymentResponse> result, PisPaymentCancellationRequest request) { if (!result.hasError()) { CancelPaymentResponse response = result.getBody(); boolean isScaRequired = cancellationScaNeededDecider.isScaRequired(response.isStartAuthorisationRequired()); if (isStartAuthorisationLinksNeeded(isScaRequired, response.getTransactionStatus())) { boolean isExplicitMethod = authorisationMethodDecider.isExplicitMethod(request.getTppExplicitAuthorisationPreferred(), false); response.setLinks(new PaymentCancellationLinks(getHttpUrl(), scaApproachResolver, redirectLinkBuilder, redirectIdService, response, isExplicitMethod, getScaRedirectFlow(), isAuthorisationConfirmationRequestMandated(), requestProviderService.getInstanceId())); } } return result; } @Autowired  PaymentCancellationAspectService(PaymentCancellationAuthorisationNeededDecider cancellationScaNeededDecider,
                                            AspspProfileServiceWrapper aspspProfileServiceWrapper,
                                            ScaApproachResolver scaApproachResolver,
                                            RedirectLinkBuilder redirectLinkBuilder,
                                            AuthorisationMethodDecider authorisationMethodDecider,
                                            RedirectIdService redirectIdService,
                                            RequestProviderService requestProviderService); ResponseObject<CancelPaymentResponse> cancelPayment(ResponseObject<CancelPaymentResponse> result, PisPaymentCancellationRequest request);  }### Answer:
@Test void cancelPayment_status_RJCT() { response.setTransactionStatus(TransactionStatus.RJCT); responseObject = ResponseObject.<CancelPaymentResponse>builder() .body(response) .build(); ResponseObject<CancelPaymentResponse> actualResponse = service.cancelPayment(responseObject, paymentCancellationRequest); assertFalse(actualResponse.hasError()); assertEquals(actualResponse.getBody(), response); }
@Test void cancelPayment_success() { JsonReader jsonReader = new JsonReader(); AspspSettings aspspSettings = jsonReader.getObjectFromFile("json/aspect/aspsp-settings.json", AspspSettings.class); when(aspspProfileServiceWrapper.isForceXs2aBaseLinksUrl()).thenReturn(aspspSettings.getCommon().isForceXs2aBaseLinksUrl()); when(aspspProfileServiceWrapper.getXs2aBaseLinksUrl()).thenReturn(aspspSettings.getCommon().getXs2aBaseLinksUrl()); when(cancellationScaNeededDecider.isScaRequired(true)).thenReturn(true); when(authorisationMethodDecider.isExplicitMethod(false, false)).thenReturn(false); when(scaApproachResolver.resolveScaApproach()).thenReturn(ScaApproach.EMBEDDED); PaymentCancellationLinks links = new PaymentCancellationLinks(HTTP_URL, scaApproachResolver, redirectLinkBuilder, redirectIdService, response, false, ScaRedirectFlow.REDIRECT, false, ""); responseObject = ResponseObject.<CancelPaymentResponse>builder() .body(response) .build(); ResponseObject<CancelPaymentResponse> actualResponse = service.cancelPayment(responseObject, paymentCancellationRequest); assertFalse(actualResponse.hasError()); assertEquals(actualResponse.getBody().getLinks(), links); }
@Test void createPisAuthorizationAspect_withError_shouldAddTextErrorMessage() { responseObject = ResponseObject.<CancelPaymentResponse>builder() .fail(AIS_400, of(CONSENT_UNKNOWN_400)) .build(); ResponseObject<CancelPaymentResponse> actualResponse = service.cancelPayment(responseObject, paymentCancellationRequest); assertTrue(actualResponse.hasError()); }