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.events.OrderFraudCustomerNotificationEvent;
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.Matchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;


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

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

    @InjectMocks
    private BrainTreeNotifyCustomerAboutFraudAction action;

    @Mock
    private OrderProcessModel process;

    @Mock
    private OrderModel order;

    @Test
    public void testExecuteAction() {
        //given
        when(process.getOrder()).thenReturn(order);

        //when
        action.executeAction(process);

        //then
        verify(eventService).publishEvent(any(OrderFraudCustomerNotificationEvent.class));
        verify(modelService).save(order);
        verify(order).setStatus(OrderStatus.SUSPENDED);
    }

}
