package com.braintree.populators;

import com.braintree.command.result.BrainTreeTransactionResult;
import com.braintreegateway.Transaction;
import de.hybris.bootstrap.annotations.UnitTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.math.BigDecimal;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

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

    private static final String TRANSACTION_ID = "transactionId";
    private static final String GRAPHQL_ID = "GraphQLId";
    private static final BigDecimal TOTAL_AMOUNT = new BigDecimal(100);
    private static final Transaction.Status TEST_TRANSCTION_STATUS = Transaction.Status.AUTHORIZED;

    @InjectMocks
    private TransactionToBraintreeTransactionResultPopulator unit;

    @Mock
    private Transaction transaction;

    @Before
    public void setUp() {
        when(transaction.getStatus()).thenReturn(TEST_TRANSCTION_STATUS);
        when(transaction.getAmount()).thenReturn(TOTAL_AMOUNT);
        when(transaction.getId()).thenReturn(TRANSACTION_ID);
        when(transaction.getGraphQLId()).thenReturn(GRAPHQL_ID);
    }

    @Test
    public void shouldPopulateTransactionToBraintreeTransactionResult() {
        BrainTreeTransactionResult brainTreeTransactionResult = new BrainTreeTransactionResult();

        unit.populate(transaction, brainTreeTransactionResult);

        assertEquals(TEST_TRANSCTION_STATUS.name(), brainTreeTransactionResult.getStatus());
        assertEquals(TOTAL_AMOUNT, brainTreeTransactionResult.getTotalAmount());
        assertEquals(TRANSACTION_ID, brainTreeTransactionResult.getId());
        assertEquals(GRAPHQL_ID, brainTreeTransactionResult.getGraphQLId());
    }
}
