package com.braintree.converters.populators;

import com.braintree.model.BrainTreePaymentInfoModel;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.commercefacades.order.data.CCPaymentInfoData;
import de.hybris.platform.commercefacades.order.data.CartData;
import de.hybris.platform.core.model.order.CartModel;
import de.hybris.platform.core.model.order.payment.PaymentInfoModel;
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.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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

    @Mock
    private CartModel model;
    @Mock
    private BrainTreePaymentInfoModel brainTreePaymentInfoModel;
    @Mock
    private PaymentInfoModel paymentInfoModel;
    @Mock
    private Converter<BrainTreePaymentInfoModel, CCPaymentInfoData> brainTreePaymentInfoConverter;
    @InjectMocks
    private BraintreeExtendedPaymentInfoPopulator unit;

    @Test
    public void shouldPopulateExtendedPaymentInfo() {
        CartData data = new CartData();
        CCPaymentInfoData paymentInfoData = new CCPaymentInfoData();


        when(model.getPaymentInfo()).thenReturn(brainTreePaymentInfoModel);
        when(brainTreePaymentInfoConverter.convert(brainTreePaymentInfoModel)).thenReturn(paymentInfoData);

        unit.populate(model, data);

        verify(brainTreePaymentInfoConverter).convert(brainTreePaymentInfoModel);
        assertEquals(paymentInfoData, data.getPaymentInfo());
    }

    @Test
    public void shouldNotPopulateExtendedPaymentInfo() {
        CartData data = new CartData();
        CCPaymentInfoData paymentInfoData = new CCPaymentInfoData();

        when(model.getPaymentInfo()).thenReturn(paymentInfoModel);

        unit.populate(model, data);

        verify(brainTreePaymentInfoConverter, never()).convert(brainTreePaymentInfoModel);
    }
}