package com.braintree.cart.factory.impl;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.commerceservices.util.GuidKeyGenerator;
import de.hybris.platform.core.model.order.CartModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.junit.Assert.assertEquals;

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

    private static final String GUID = "GUID";

    @Mock
    private GuidKeyGenerator guidGenerator;

    @Spy
    @InjectMocks
    private DefaultBraintreeCartFactory unit;

    @Test
    public void createCartInternal() {
        CartModel cart = mock(CartModel.class);

        doReturn(cart).when(unit).getCreateCartInternal();
        when(guidGenerator.generate()).thenReturn(GUID);

        CartModel result = unit.createCartInternal();

        assertEquals(cart, result);
        verify(cart).setBrainTreeOrderId(GUID);
    }
}
