### Question:
UpdatePaymentAfterSpiServiceInternalEncrypted implements UpdatePaymentAfterSpiServiceEncrypted { @Override @Transactional public CmsResponse<Boolean> updatePaymentCancellationTppRedirectUri(@NotNull String encryptedPaymentId, @NotNull TppRedirectUri tppRedirectUri) { Optional<String> decryptIdOptional = securityDataService.decryptId(encryptedPaymentId); if (decryptIdOptional.isEmpty()) { log.info("Encrypted Payment ID [{}]. Update cancellation payment tpp redirect URIs by id failed, couldn't decrypt payment id", encryptedPaymentId); return CmsResponse.<Boolean>builder() .error(TECHNICAL_ERROR) .build(); } return updatePaymentStatusAfterSpiService.updatePaymentCancellationTppRedirectUri(decryptIdOptional.get(), tppRedirectUri); }  @Override @Transactional CmsResponse<Boolean> updatePaymentStatus(@NotNull String encryptedPaymentId, @NotNull TransactionStatus status); @Override @Transactional CmsResponse<Boolean> updatePaymentCancellationTppRedirectUri(@NotNull String encryptedPaymentId, @NotNull TppRedirectUri tppRedirectUri); @Override @Transactional CmsResponse<Boolean> updatePaymentCancellationInternalRequestId(@NotNull String encryptedPaymentId, @NotNull String internalRequestId);  }### Answer:
@Test void updatePaymentCancellationTppRedirectUri_success() { when(securityDataService.decryptId(ENCRYPTED_PAYMENT_ID)).thenReturn(Optional.of(DECRYPTED_PAYMENT_ID)); when(updatePaymentStatusAfterSpiService.updatePaymentCancellationTppRedirectUri(eq(DECRYPTED_PAYMENT_ID), eq(tppRedirectUri))) .thenReturn(CmsResponse.<Boolean>builder() .payload(true) .build()); CmsResponse<Boolean> actual = updatePaymentStatusAfterSpiServiceInternalEncrypted.updatePaymentCancellationTppRedirectUri(ENCRYPTED_PAYMENT_ID, tppRedirectUri); assertTrue(actual.isSuccessful()); assertTrue(actual.getPayload()); verify(securityDataService, times(1)).decryptId(ENCRYPTED_PAYMENT_ID); verify(updatePaymentStatusAfterSpiService, times(1)).updatePaymentCancellationTppRedirectUri(eq(DECRYPTED_PAYMENT_ID), eq(tppRedirectUri)); }
@Test void updatePaymentCancellationTppRedirectUri_failure_wrongPaymentId() { when(securityDataService.decryptId(WRONG_ENCRYPTED_PAYMENT_ID)).thenReturn(Optional.of(WRONG_DECRYPTED_PAYMENT_ID)); when(updatePaymentStatusAfterSpiService.updatePaymentCancellationTppRedirectUri(eq(WRONG_DECRYPTED_PAYMENT_ID), eq(tppRedirectUri))) .thenReturn(CmsResponse.<Boolean>builder() .payload(false) .build()); CmsResponse<Boolean> actual = updatePaymentStatusAfterSpiServiceInternalEncrypted.updatePaymentCancellationTppRedirectUri(WRONG_ENCRYPTED_PAYMENT_ID, tppRedirectUri); assertTrue(actual.isSuccessful()); assertFalse(actual.getPayload()); verify(securityDataService, times(1)).decryptId(WRONG_ENCRYPTED_PAYMENT_ID); verify(updatePaymentStatusAfterSpiService, times(1)).updatePaymentCancellationTppRedirectUri(eq(WRONG_DECRYPTED_PAYMENT_ID), eq(tppRedirectUri)); }
@Test void updatePaymentCancellationTppRedirectUri_failure_decryptionFailed() { when(securityDataService.decryptId(ENCRYPTED_PAYMENT_ID)).thenReturn(Optional.empty()); CmsResponse<Boolean> actual = updatePaymentStatusAfterSpiServiceInternalEncrypted.updatePaymentCancellationTppRedirectUri(ENCRYPTED_PAYMENT_ID, tppRedirectUri); assertTrue(actual.hasError()); assertEquals(CmsError.TECHNICAL_ERROR, actual.getError()); verify(securityDataService, times(1)).decryptId(ENCRYPTED_PAYMENT_ID); verify(updatePaymentStatusAfterSpiService, never()).updatePaymentCancellationTppRedirectUri(eq(DECRYPTED_PAYMENT_ID), eq(tppRedirectUri)); }