package com.braintree.email.emailServices;

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

import com.braintree.email.emailEvents.BraintreeLocalPaymentReversedEmailEvent;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.basecommerce.model.site.BaseSiteModel;
import de.hybris.platform.core.model.c2l.CurrencyModel;
import de.hybris.platform.core.model.c2l.LanguageModel;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.core.model.user.CustomerModel;
import de.hybris.platform.servicelayer.event.EventService;
import de.hybris.platform.servicelayer.i18n.CommonI18NService;
import de.hybris.platform.site.BaseSiteService;
import de.hybris.platform.store.BaseStoreModel;
import de.hybris.platform.store.services.BaseStoreService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

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

    private static final String ORDER_CODE = "2412";
    private static final String RESULT_CONTENT = "Your Order " + ORDER_CODE + " was not placed successful - Automated Message - DO NOT REPLY";

    @Mock
    private EventService eventService;

    @Mock
    private BaseSiteService baseSiteService;

    @Mock
    private BaseStoreService baseStoreService;

    @Mock
    private CommonI18NService commonI18NService;

    @Captor
    private ArgumentCaptor<BraintreeLocalPaymentReversedEmailEvent> localPaymentReversedEmailEventCaptor;

    @InjectMocks
    private BraintreeLocalPaymentReversedEmailEventService unit;

    @Test
    public void shouldSendBraintreeLocalPaymentReversedEmailEvent() {
        final CustomerModel customerModel = mock(CustomerModel.class);
        final OrderModel orderModel = mock(OrderModel.class);
        final BaseStoreModel baseStoreModel = mock(BaseStoreModel.class);
        final BaseSiteModel baseSiteModel = mock(BaseSiteModel.class);
        final LanguageModel languageModel = mock(LanguageModel.class);
        final CurrencyModel currencyModel = mock(CurrencyModel.class);

        when(orderModel.getStore()).thenReturn(baseStoreModel);
        when(orderModel.getSite()).thenReturn(baseSiteModel);
        when(orderModel.getLanguage()).thenReturn(languageModel);
        when(orderModel.getCurrency()).thenReturn(currencyModel);
        when(orderModel.getCode()).thenReturn(ORDER_CODE);

        unit.sendBraintreeLocalPaymentReversedEmailEvent(customerModel, orderModel);

        verify(eventService).publishEvent(localPaymentReversedEmailEventCaptor.capture());

        final BraintreeLocalPaymentReversedEmailEvent event = localPaymentReversedEmailEventCaptor.getValue();

        assertEquals(baseStoreModel, event.getBaseStore());
        assertEquals(baseSiteModel, event.getSite());
        assertEquals(customerModel, event.getCustomer());
        assertEquals(languageModel, event.getLanguage());
        assertEquals(currencyModel, event.getCurrency());
        assertEquals(RESULT_CONTENT, event.getContent());
        assertEquals(orderModel, event.getOrderModel());
    }

}
