package com.braintree.actions.consignment;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.orderprocessing.model.OrderProcessModel;
import de.hybris.platform.ordersplitting.model.ConsignmentProcessModel;
import de.hybris.platform.processengine.BusinessProcessService;
import de.hybris.platform.servicelayer.model.ModelService;
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.mockito.Matchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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

    @Mock
    private BusinessProcessService businessProcessService;
    @Mock
    private ModelService modelService;

    @InjectMocks
    private BrainTreeSubprocessEndAction unit;

    @Mock
    private ConsignmentProcessModel process;
    @Mock
    private OrderProcessModel parentProcess;

    @Test
    public void shouldExecuteAction() {
        //given
        when(process.getParentProcess()).thenReturn(parentProcess);

        //when
        unit.executeAction(process);

        //then
        verify(modelService).save(process);
        verify(process).setDone(true);
        verify(businessProcessService).triggerEvent(anyString());
    }

}
