EscPaymentManagerImp implements EscPaymentManager { @Override public boolean manageEscForError(final MercadoPagoError error, final List<PaymentData> paymentDataList) { boolean result = false; for (final PaymentData paymentData : paymentDataList) { final boolean isInvalidEsc = paymentData.containsCardInfo() && EscUtil.isErrorInvalidPaymentWithEsc(error); if (isInvalidEsc) { escManager.deleteESCWith(paymentData.getToken().getCardId(), EscDeleteReason.REJECTED_PAYMENT, ApiException.ErrorCodes.INVALID_PAYMENT_WITH_ESC); } result |= isInvalidEsc; } return result; } EscPaymentManagerImp(@NonNull final ESCManagerBehaviour escManager,
        @NonNull final PaymentSettingRepository paymentSettingRepository); @Override boolean hasEsc(@NonNull final Card card); @Override boolean manageEscForPayment(final List<PaymentData> paymentDataList, final String paymentStatus,
        final String paymentStatusDetail); @Override boolean manageEscForError(final MercadoPagoError error, final List<PaymentData> paymentDataList);  }
@Test public void whenManageEscForErrorHasCardPaymentDataBadRequestWithCauseInvalidEscDeleteEscAndReturnTrue() { final PaymentData paymentData = validCardPaymentData(); final MercadoPagoError error = escMpError(); final boolean invalid = escPaymentManager.manageEscForError(error, Collections.singletonList(paymentData)); verify(escManagerBehaviour).deleteESCWith(paymentData.getToken().getCardId(), EscDeleteReason.REJECTED_PAYMENT, ApiException.ErrorCodes.INVALID_PAYMENT_WITH_ESC); verifyNoMoreInteractions(escManagerBehaviour); assertTrue(invalid); }
@Test public void whenManageEscForErrorHasCardPaymentDataBadRequestWithMultipleCauseAndInvalidEscDeleteEscAndReturnTrue() { final PaymentData paymentData = validCardPaymentData(); final MercadoPagoError error = multipleErrorEscMpError(); final boolean invalid = escPaymentManager.manageEscForError(error, Collections.singletonList(paymentData)); verify(escManagerBehaviour).deleteESCWith(paymentData.getToken().getCardId(), EscDeleteReason.REJECTED_PAYMENT, ApiException.ErrorCodes.INVALID_PAYMENT_WITH_ESC); verifyNoMoreInteractions(escManagerBehaviour); assertTrue(invalid); }
@Test public void whenManageEscForErrorHasCardPaymentDataBadRequestWithNoEscCauseReturnFalse() { final PaymentData paymentData = validCardPaymentData(); final MercadoPagoError error = noEscMpError(); final boolean invalid = escPaymentManager.manageEscForError(error, Collections.singletonList(paymentData)); verifyNoMoreInteractions(escManagerBehaviour); assertFalse(invalid); }
@Test public void whenManageEscForErrorNoCardPaymentDataBadRequestWithNoEscCauseReturnFalse() { final PaymentData paymentData = mock(PaymentData.class); final MercadoPagoError error = noEscMpError(); final boolean invalid = escPaymentManager.manageEscForError(error, Collections.singletonList(paymentData)); verifyNoMoreInteractions(escManagerBehaviour); assertFalse(invalid); }