package com.braintree.customersupportbackoffice.actions.transaction.clone;

import com.braintree.customersupportbackoffice.services.BrainTreeTransactionManagementActionService;
import com.braintree.model.BrainTreeTransactionDetailModel;
import com.hybris.cockpitng.actions.ActionContext;
import com.hybris.cockpitng.actions.ActionResult;
import com.hybris.cockpitng.engine.impl.ComponentWidgetAdapter;
import de.hybris.bootstrap.annotations.UnitTest;
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.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class BrainTreeCloneTransactionActionTest {
    @Mock
    private BrainTreeTransactionManagementActionService brainTreeTransactionManagementActionService;
    @Mock
    private ComponentWidgetAdapter componentWidgetAdapter;

    @InjectMocks
    private BrainTreeCloneTransactionAction unit;

    @Mock
    private ActionContext<BrainTreeTransactionDetailModel> actionContext;
    @Mock
    private BrainTreeTransactionDetailModel transactionDetail;

    @Test
    public void shouldSuccessfullyPerform() {
        ActionResult<BrainTreeTransactionDetailModel> result = unit.perform(actionContext);

        assertEquals(ActionResult.SUCCESS, result.getResultCode());
    }

    @Test
    public void shouldReturnTrueIfCloneActionPossible() {
        when(actionContext.getData()).thenReturn(transactionDetail);
        when(brainTreeTransactionManagementActionService.isClonePossible(transactionDetail)).thenReturn(true);

        boolean result = unit.canPerform(actionContext);

        assertTrue(result);
    }


}