package com.braintree.listeners;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.orderprocessing.events.PickupConfirmationEvent;
import de.hybris.platform.ordersplitting.model.ConsignmentModel;
import de.hybris.platform.ordersplitting.model.ConsignmentProcessModel;
import de.hybris.platform.processengine.BusinessProcessService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.List;

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

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

    private static final String CODE = "CODE";
    private static final String CODE_CONSIGNMENT_PICKUP = "CODE_ConsignmentPickup";
    @Mock
    private BusinessProcessService businessProcessService;

    @InjectMocks
    private BrainTreePickupConfirmationEventListener unit;

    @Mock
    private PickupConfirmationEvent pickupConfirmationEvent;
    @Mock
    private ConsignmentProcessModel consignmentProcessModel;
    @Mock
    private ConsignmentModel consignmentModel;

    @Test
    public void shouldExecuteOnEvent() {
        //given
        when(pickupConfirmationEvent.getProcess()).thenReturn(consignmentProcessModel);
        when(consignmentProcessModel.getConsignment()).thenReturn(consignmentModel);
        when(consignmentModel.getConsignmentProcesses()).thenReturn(List.of(consignmentProcessModel));
        when(consignmentProcessModel.getCode()).thenReturn(CODE);

        //when
        unit.onEvent(pickupConfirmationEvent);

        //then
        verify(businessProcessService).triggerEvent(CODE_CONSIGNMENT_PICKUP);
    }

}
