PaymentServiceHandlerWrapper implements PaymentServiceHandler { @VisibleForTesting @NonNull IPaymentDescriptorHandler getHandler() { return paymentHandler; } PaymentServiceHandlerWrapper(
        @NonNull final PaymentRepository paymentRepository,
        @NonNull final DisabledPaymentMethodRepository disabledPaymentMethodRepository,
        @NonNull final EscPaymentManager escPaymentManager,
        @NonNull final InstructionsRepository instructionsRepository,
        @NonNull final CongratsRepository congratsRepository,
        @NonNull final UserSelectionRepository userSelectionRepository); PaymentServiceEventHandler getObservableEvents(); void createTransactionLiveData(); void setHandler(@Nullable final PaymentServiceHandler handler); void detach(@Nullable final PaymentServiceHandler handler); @Override void onCvvRequired(@NonNull final Card card, @NonNull final Reason reason); @Override void onVisualPayment(); @Override void onRecoverPaymentEscInvalid(final PaymentRecovery recovery); @Override void onPaymentFinished(@NonNull final IPaymentDescriptor payment); @Override void onPostPayment(@NonNull final PaymentModel paymentModel); @Override void onPaymentError(@NonNull final MercadoPagoError error); void processMessages();  }
@Test public void whenPaymentFinishedWithPaymentVerifyEscManaged() { final PaymentResult paymentResult = mock(PaymentResult.class); final Payment payment = mock(Payment.class); when(paymentResult.isOffPayment()).thenReturn(false); when(paymentRepository.createPaymentResult(payment)).thenReturn(paymentResult); final IPaymentDescriptorHandler handler = paymentServiceHandlerWrapper.getHandler(); handler.visit(payment); verify(escPaymentManager) .manageEscForPayment(paymentRepository.getPaymentDataList(), payment.getPaymentStatus(), payment.getPaymentStatusDetail()); verify(paymentRepository).createPaymentResult(payment); verify(paymentRepository).storePayment(payment); verify(paymentRepository, times(2)).getPaymentDataList(); verifyOnPaymentFinished(payment, paymentResult); noMoreInteractions(); }
@Test public void whenPaymentFinishedWithBusinessVerifyEscManaged() { final BusinessPayment payment = mock(BusinessPayment.class); final PaymentResult paymentResult = mock(PaymentResult.class); when(paymentRepository.createPaymentResult(payment)).thenReturn(paymentResult); final IPaymentDescriptorHandler handler = paymentServiceHandlerWrapper.getHandler(); handler.visit(payment); verify(escPaymentManager) .manageEscForPayment(paymentRepository.getPaymentDataList(), payment.getPaymentStatus(), payment.getPaymentStatusDetail()); verify(paymentRepository).storePayment(payment); verify(paymentRepository).createPaymentResult(payment); verify(paymentRepository, times(2)).getPaymentDataList(); verifyOnPaymentFinished(payment, paymentResult); noMoreInteractions(); }
@Test public void whenPaymentFinishedWithGenericPaymentVerifyEscManaged() { final PaymentResult paymentResult = mock(PaymentResult.class); final IPaymentDescriptor payment = mock(IPaymentDescriptor.class); when(paymentResult.isOffPayment()).thenReturn(false); when(paymentRepository.createPaymentResult(payment)).thenReturn(paymentResult); final IPaymentDescriptorHandler handler = paymentServiceHandlerWrapper.getHandler(); handler.visit(payment); verify(escPaymentManager) .manageEscForPayment(paymentRepository.getPaymentDataList(), payment.getPaymentStatus(), payment.getPaymentStatusDetail()); verify(paymentRepository).storePayment(payment); verify(paymentRepository).createPaymentResult(payment); verify(paymentRepository, times(2)).getPaymentDataList(); verifyOnPaymentFinished(payment, paymentResult); noMoreInteractions(); }