### Question:
UpdatePaymentAfterSpiServiceInternal implements UpdatePaymentAfterSpiService { @Override @Transactional public CmsResponse<Boolean> updatePaymentCancellationTppRedirectUri(@NotNull String paymentId, @NotNull TppRedirectUri tppRedirectUri) { Optional<PisCommonPaymentData> paymentDataOptional = commonPaymentDataService.getPisCommonPaymentData(paymentId, null); if (paymentDataOptional.isEmpty() || paymentDataOptional.get().isFinalised()) { log.info("Payment ID [{}]. Update payment status by id failed, because pis payment data not found or payment is finalized", paymentId); return CmsResponse.<Boolean>builder() .payload(false) .build(); } boolean updated = commonPaymentDataService.updateCancelTppRedirectURIs(paymentDataOptional.get(), tppRedirectUri); return CmsResponse.<Boolean>builder() .payload(updated) .build(); }  @Override @Transactional CmsResponse<Boolean> updatePaymentStatus(@NotNull String paymentId, @NotNull TransactionStatus status); @Override @Transactional CmsResponse<Boolean> updatePaymentCancellationTppRedirectUri(@NotNull String paymentId, @NotNull TppRedirectUri tppRedirectUri); @Override @Transactional CmsResponse<Boolean> updatePaymentCancellationInternalRequestId(@NotNull String paymentId, @NotNull String internalRequestId);  }### Answer:
@Test void updatePaymentCancellationTppRedirectUri_success() { pisCommonPaymentData.setTransactionStatus(TransactionStatus.ACCP); when(commonPaymentDataService.getPisCommonPaymentData(PAYMENT_ID, null)).thenReturn(Optional.of(pisCommonPaymentData)); when(commonPaymentDataService.updateCancelTppRedirectURIs(pisCommonPaymentData, tppRedirectUri)).thenReturn(true); CmsResponse<Boolean> actual = updatePaymentAfterSpiServiceInternal.updatePaymentCancellationTppRedirectUri(PAYMENT_ID, tppRedirectUri); assertTrue(actual.isSuccessful()); assertTrue(actual.getPayload()); verify(commonPaymentDataService, times(1)).getPisCommonPaymentData(anyString(), isNull()); verify(commonPaymentDataService, times(1)).updateCancelTppRedirectURIs(eq(pisCommonPaymentData), eq(tppRedirectUri)); }
@Test void updatePaymentCancellationTppRedirectUri_transactionStatusIsFinalised() { pisCommonPaymentData.setTransactionStatus(TransactionStatus.RJCT); when(commonPaymentDataService.getPisCommonPaymentData(PAYMENT_ID, null)).thenReturn(Optional.of(pisCommonPaymentData)); CmsResponse<Boolean> actual = updatePaymentAfterSpiServiceInternal.updatePaymentCancellationTppRedirectUri(PAYMENT_ID, tppRedirectUri); assertTrue(actual.isSuccessful()); assertFalse(actual.getPayload()); verify(commonPaymentDataService, times(1)).getPisCommonPaymentData(anyString(), isNull()); verify(commonPaymentDataService, never()).updateCancelTppRedirectURIs(any(PisCommonPaymentData.class), eq(tppRedirectUri)); }
@Test void updatePaymentCancellationTppRedirectUri_paymentDataIsEmpty() { when(commonPaymentDataService.getPisCommonPaymentData(PAYMENT_ID, null)).thenReturn(Optional.empty()); CmsResponse<Boolean> actual = updatePaymentAfterSpiServiceInternal.updatePaymentCancellationTppRedirectUri(PAYMENT_ID, tppRedirectUri); assertTrue(actual.isSuccessful()); assertFalse(actual.getPayload()); verify(commonPaymentDataService, times(1)).getPisCommonPaymentData(anyString(), isNull()); verify(commonPaymentDataService, never()).updateCancelTppRedirectURIs(any(PisCommonPaymentData.class), eq(tppRedirectUri)); }