package com.braintree.converters.populators;

import com.braintree.model.BrainTreePaymentInfoModel;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.commercefacades.order.data.AbstractOrderData;
import de.hybris.platform.commercefacades.order.data.CCPaymentInfoData;
import de.hybris.platform.core.model.order.AbstractOrderModel;
import de.hybris.platform.core.model.order.payment.CreditCardPaymentInfoModel;
import de.hybris.platform.servicelayer.dto.converter.Converter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class BrainTreeOrderPopulatorTest {

    @Mock
    private Converter<BrainTreePaymentInfoModel, CCPaymentInfoData> brainTreePaymentInfoConverter;
    @Mock
    private Converter<CreditCardPaymentInfoModel, CCPaymentInfoData> creditCardPaymentInfoConverter;
    @InjectMocks
    private BrainTreeOrderPopulator unit;

    @Test
    public void addPaymentInformationShouldUseCreditCardConverterIfOrderHaveCreditCardInfoModel() {
        final AbstractOrderModel orderModel = Mockito.mock(AbstractOrderModel.class);
        final AbstractOrderData result = new AbstractOrderData();
        final CreditCardPaymentInfoModel cardPaymentInfoModel = Mockito.mock(CreditCardPaymentInfoModel.class);
        when(orderModel.getPaymentInfo()).thenReturn(cardPaymentInfoModel);

        unit.addPaymentInformation(orderModel, result);
        verify(creditCardPaymentInfoConverter).convert(cardPaymentInfoModel);
    }

    @Test
    public void addPaymentInformationShouldUseBraintreePaymentConverterIfOrderHaveBraintreeInfoModel() {
        final AbstractOrderModel orderModel = Mockito.mock(AbstractOrderModel.class);
        final AbstractOrderData result = new AbstractOrderData();
        final BrainTreePaymentInfoModel cardPaymentInfoModel = Mockito.mock(BrainTreePaymentInfoModel.class);
        when(orderModel.getPaymentInfo()).thenReturn(cardPaymentInfoModel);

        unit.addPaymentInformation(orderModel, result);
        verify(brainTreePaymentInfoConverter).convert(cardPaymentInfoModel);
    }
}
