package com.braintree.actions.order;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.enums.OrderStatus;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.orderprocessing.model.OrderProcessModel;
import de.hybris.platform.servicelayer.event.EventService;
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.Mockito.verify;
import static org.mockito.Mockito.when;

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

    @Mock
    private ModelService modelService;
    @Mock
    private EventService eventService;

    @InjectMocks
    private BrainTreePrepareOrderForManualCheckAction prepareOrderForManualCheck;

    @Mock
    private OrderProcessModel orderProcess;

    @Mock
    private OrderModel order;

    @Test
    public void testExecute() throws Exception {
        //given
        when(orderProcess.getOrder()).thenReturn(order);

        //when
        prepareOrderForManualCheck.executeAction(orderProcess);

        //then
        verify(order).setStatus(OrderStatus.WAIT_FRAUD_MANUAL_CHECK);
        verify(modelService).save(order);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testExecuteNullProcess() throws Exception {
        prepareOrderForManualCheck.executeAction(null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testExecuteNullOrder() throws Exception {
        prepareOrderForManualCheck.executeAction(new OrderProcessModel());
    }

}
