package com.braintree.facade.impl;

import com.braintree.event.BraintreeLinkCustomerNotificationEvent;
import com.braintree.event.BraintreeUnlinkCustomerNotificationEvent;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.servicelayer.event.EventService;
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;

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

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

    private static final String UID = "uid";

    @Mock
    private EventService eventService;

    @Captor
    private ArgumentCaptor<BraintreeLinkCustomerNotificationEvent> linkEmailCaptor;
    @Captor
    private ArgumentCaptor<BraintreeUnlinkCustomerNotificationEvent> unlinkEmailCaptor;

    @InjectMocks
    private DefaultBraintreeConnectWithPayPalNotificationFacade unit;

    @Test
    public void shouldSendLinkCustomerEmail() {
        unit.sendLinkCustomerEmailNotification(UID);

        verify(eventService).publishEvent(linkEmailCaptor.capture());
        assertEquals(UID, linkEmailCaptor.getValue().getUid());
    }

    @Test
    public void shouldSendUnlinkCustomerEmail() {
        unit.sendUnlinkCustomerEmailNotification(UID);

        verify(eventService).publishEvent(unlinkEmailCaptor.capture());
        assertEquals(UID, unlinkEmailCaptor.getValue().getUid());
    }

}