### Question:
PaymentCancellationSpiImpl extends AbstractAuthorisationSpi<SpiPayment, SCAPaymentResponseTO> implements PaymentCancellationSpi { @Override public @NotNull SpiResponse<SpiPaymentCancellationResponse> initiatePaymentCancellation(@NotNull SpiContextData contextData, @NotNull SpiPayment payment, @NotNull SpiAspspConsentDataProvider aspspConsentDataProvider) { SpiPaymentCancellationResponse response = new SpiPaymentCancellationResponse(); boolean cancellationMandated = payment.getPaymentStatus() != TransactionStatus.RCVD; response.setCancellationAuthorisationMandated(cancellationMandated); response.setTransactionStatus(payment.getPaymentStatus()); return SpiResponse.<SpiPaymentCancellationResponse>builder() .payload(response).build(); } PaymentCancellationSpiImpl(PaymentRestClient ledgersRestClient,
                                      TokenStorageService tokenStorageService, ScaMethodConverter scaMethodConverter,
                                      AuthRequestInterceptor authRequestInterceptor, AspspConsentDataService consentDataService,
                                      GeneralAuthorisationService authorisationService,
                                      FeignExceptionReader feignExceptionReader, ScaLoginMapper scaLoginMapper); @Override @NotNull SpiResponse<SpiPaymentCancellationResponse> initiatePaymentCancellation(@NotNull SpiContextData contextData,
                                                                                            @NotNull SpiPayment payment,
                                                                                            @NotNull SpiAspspConsentDataProvider aspspConsentDataProvider); @Override @NotNull SpiResponse<SpiResponse.VoidResponse> cancelPaymentWithoutSca(@NotNull SpiContextData contextData,
                                                                                  @NotNull SpiPayment payment,
                                                                                  @NotNull SpiAspspConsentDataProvider aspspConsentDataProvider); @Override @NotNull SpiResponse<SpiPaymentExecutionResponse> verifyScaAuthorisationAndCancelPaymentWithResponse(@NotNull SpiContextData contextData,
                                                                                                                @NotNull SpiScaConfirmation spiScaConfirmation,
                                                                                                                @NotNull SpiPayment payment,
                                                                                                                @NotNull SpiAspspConsentDataProvider aspspConsentDataProvider); @Override @NotNull SpiResponse<Boolean> requestTrustedBeneficiaryFlag(@NotNull SpiContextData spiContextData, @NotNull SpiPayment payment, @NotNull String authorisationId, @NotNull SpiAspspConsentDataProvider spiAspspConsentDataProvider);  }### Answer:
@Test void initiatePaymentCancellation_transactionStatusRCVD() { businessObject.setPaymentStatus(TransactionStatus.RCVD); SpiResponse<SpiPaymentCancellationResponse> actual = authorisationSpi.initiatePaymentCancellation(SPI_CONTEXT_DATA, businessObject, spiAspspConsentDataProvider); assertFalse(actual.hasError()); assertNotNull(actual.getPayload()); assertEquals(TransactionStatus.RCVD, actual.getPayload().getTransactionStatus()); assertFalse(actual.getPayload().isCancellationAuthorisationMandated()); }
@Test void initiatePaymentCancellation_transactionStatusAnotherFromRCVD() { businessObject.setPaymentStatus(TransactionStatus.ACSP); SpiResponse<SpiPaymentCancellationResponse> actual = authorisationSpi.initiatePaymentCancellation(SPI_CONTEXT_DATA, businessObject, spiAspspConsentDataProvider); assertFalse(actual.hasError()); assertNotNull(actual.getPayload()); assertEquals(TransactionStatus.ACSP, actual.getPayload().getTransactionStatus()); assertTrue(actual.getPayload().isCancellationAuthorisationMandated()); }