package com.braintree.strategy.impl;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.model.order.AbstractOrderEntryModel;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.core.model.user.AddressModel;
import de.hybris.platform.ordersplitting.model.ConsignmentModel;
import de.hybris.platform.storelocator.model.PointOfServiceModel;
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.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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

    @InjectMocks
    private BrainTreeSplitByEntryDeliveryAddress unit;

    @Mock
    private AbstractOrderEntryModel orderEntry;
    @Mock
    private AddressModel addressModel;
    @Mock
    private PointOfServiceModel pointOfServiceModel;
    @Mock
    private OrderModel orderModel;
    @Mock
    private ConsignmentModel consignmentModel;


    @Test
    public void shouldGetDeliveryAddressFormOrderEntry() {
        //given
        when(orderEntry.getDeliveryAddress()).thenReturn(addressModel);

        //when
        AddressModel result = (AddressModel) unit.getGroupingObject(orderEntry);

        //then
        assertEquals(addressModel, result);
    }

    @Test
    public void shouldGetDeliveryAddressFormPointOfServiceModel() {
        //given
        when(orderEntry.getDeliveryPointOfService()).thenReturn(pointOfServiceModel);
        when(pointOfServiceModel.getAddress()).thenReturn(addressModel);

        //when
        AddressModel result = (AddressModel) unit.getGroupingObject(orderEntry);

        //then
        assertEquals(addressModel, result);
    }

    @Test
    public void shouldGetDeliveryAddressFormPointOrderModel() {
        //given
        when(orderEntry.getOrder()).thenReturn(orderModel);
        when(orderModel.getDeliveryAddress()).thenReturn(addressModel);

        //when
        AddressModel result = (AddressModel) unit.getGroupingObject(orderEntry);

        //then
        assertEquals(addressModel, result);
    }

    @Test
    public void shouldExecuteAfterSplitting() {
        //when
        unit.afterSplitting(addressModel, consignmentModel);

        //then
        verify(consignmentModel).setShippingAddress(addressModel);
    }

}
