package com.braintree.actions.consignment;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.basecommerce.enums.ConsignmentStatus;
import de.hybris.platform.ordersplitting.model.ConsignmentModel;
import de.hybris.platform.ordersplitting.model.ConsignmentProcessModel;
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.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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

    @Mock
    private ModelService modelService;

    @InjectMocks
    private BrainTreeCancelConsignmentAction unit;

    @Mock
    private ConsignmentProcessModel process;
    @Mock
    private ConsignmentModel consignment;

    @Test
    public void shouldSetStatusCancel() {
        //given
        when(process.getConsignment()).thenReturn(consignment);

        //when
        unit.executeAction(process);

        //then
        verify(modelService).save(consignment);
        verify(consignment).setStatus(ConsignmentStatus.CANCELLED);
    }

    @Test
    public void shouldNotSetStatusIfConsignmentIsNull() {
        //when
        unit.executeAction(process);

        //then
        verify(modelService, never()).save(any(ConsignmentModel.class));
        verify(consignment, never()).setStatus(any(ConsignmentStatus.class));
    }

}
