### Question:
UpdatePaymentAfterSpiServiceInternal implements UpdatePaymentAfterSpiService { @Override @Transactional public CmsResponse<Boolean> updatePaymentStatus(@NotNull String paymentId, @NotNull TransactionStatus status) { 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.updateStatusInPaymentData(paymentDataOptional.get(), status); 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 updatePaymentStatus_success() { pisCommonPaymentData.setTransactionStatus(TransactionStatus.ACCP); when(commonPaymentDataService.getPisCommonPaymentData(PAYMENT_ID, null)).thenReturn(Optional.of(pisCommonPaymentData)); when(commonPaymentDataService.updateStatusInPaymentData(pisCommonPaymentData, TransactionStatus.ACSP)).thenReturn(true); CmsResponse<Boolean> actual = updatePaymentAfterSpiServiceInternal.updatePaymentStatus(PAYMENT_ID, TransactionStatus.ACSP); assertTrue(actual.isSuccessful()); assertTrue(actual.getPayload()); verify(commonPaymentDataService, times(1)).getPisCommonPaymentData(anyString(), isNull()); verify(commonPaymentDataService, times(1)).updateStatusInPaymentData(any(PisCommonPaymentData.class), eq(TransactionStatus.ACSP)); }
@Test void updatePaymentStatus_transactionStatusIsFinalised() { pisCommonPaymentData.setTransactionStatus(TransactionStatus.RJCT); when(commonPaymentDataService.getPisCommonPaymentData(PAYMENT_ID, null)).thenReturn(Optional.of(pisCommonPaymentData)); CmsResponse<Boolean> actual = updatePaymentAfterSpiServiceInternal.updatePaymentStatus(PAYMENT_ID, TransactionStatus.ACSP); assertTrue(actual.isSuccessful()); assertFalse(actual.getPayload()); verify(commonPaymentDataService, times(1)).getPisCommonPaymentData(anyString(), isNull()); verify(commonPaymentDataService, never()).updateStatusInPaymentData(any(PisCommonPaymentData.class), any(TransactionStatus.class)); }
@Test void updatePaymentStatus_paymentDataIsEmpty() { when(commonPaymentDataService.getPisCommonPaymentData(PAYMENT_ID, null)).thenReturn(Optional.empty()); CmsResponse<Boolean> actual = updatePaymentAfterSpiServiceInternal.updatePaymentStatus(PAYMENT_ID, TransactionStatus.ACSP); assertTrue(actual.isSuccessful()); assertFalse(actual.getPayload()); verify(commonPaymentDataService, times(1)).getPisCommonPaymentData(anyString(), isNull()); verify(commonPaymentDataService, never()).updateStatusInPaymentData(any(PisCommonPaymentData.class), any(TransactionStatus.class)); }