package com.braintree.email.context;

import com.braintree.model.BraintreeLocalPaymentReversedEmailProcessModel;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.acceleratorservices.model.cms2.pages.EmailPageModel;
import de.hybris.platform.commercefacades.user.data.CustomerData;
import de.hybris.platform.commerceservices.model.process.StoreFrontCustomerProcessModel;
import de.hybris.platform.core.model.c2l.CurrencyModel;
import de.hybris.platform.core.model.user.UserModel;
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.junit.Assert.assertNull;
import static org.mockito.Mockito.when;

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

    private static final String CONTENT = "Content";
    private static final String ORDER_ID = "OrderId";
    private static final String ORDER_TOTAL_PRICE = "2.0";
    private static final String ISO_CODE = "ISO_CODE";

    @Mock
    private transient Converter<UserModel, CustomerData> customerConverter;

    @InjectMocks
    private BraintreeLocalPaymentReversedEmailContext unit;

    @Mock
    private StoreFrontCustomerProcessModel processModel;
    @Mock
    private EmailPageModel emailPageModel;
    @Mock
    private BraintreeLocalPaymentReversedEmailProcessModel localPaymentReversedEmailProcessModel;
    @Mock
    private CurrencyModel currencyModel;

    @Test
    public void shouldInit() {
        //given
        when(localPaymentReversedEmailProcessModel.getContent()).thenReturn(CONTENT);
        when(localPaymentReversedEmailProcessModel.getOrderId()).thenReturn(ORDER_ID);
        when(localPaymentReversedEmailProcessModel.getOrderTotalPrice()).thenReturn(ORDER_TOTAL_PRICE);
        when(localPaymentReversedEmailProcessModel.getCurrency()).thenReturn(currencyModel);
        when(currencyModel.getIsocode()).thenReturn(ISO_CODE);

        //when
        unit.init(localPaymentReversedEmailProcessModel, emailPageModel);

        //then
        assertEquals(CONTENT, unit.getContent());
        assertEquals(ORDER_ID, unit.getOrderId());
        assertEquals(ORDER_TOTAL_PRICE, unit.getOrderTotalPrice());
        assertEquals(ISO_CODE, unit.getCurrency());
    }

    @Test
    public void shouldNotInitFieldsIfProcessModelNotInstanceOfBraintreeLocalPaymentReversedEmailProcessModel() {
        //when
        unit.init(processModel, emailPageModel);

        //then
        assertNull(unit.getContent());
        assertNull(unit.getOrderId());
        assertNull(unit.getOrderTotalPrice());
        assertNull(unit.getCurrency());
    }

}
