package com.braintree.converters.populators;

import com.braintree.hybris.data.BrainTreeSubscriptionInfoData;
import com.braintree.payment.dto.BraintreeInfo;
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 BrainTreeInfoPopulatorTest {

    private static final String TOKEN = "token";
    private static final String GRAPH_QL_TOKEN = "graphQLToken";
    private static final String NONCE = "nonce";
    private static final String DEVICE_DATA = "deviceData";
    private static final String IMAGE_SOURCE = "imageSource";
    private static final String EXPIRATION_MONTH = "expirationMonth";
    private static final String EXPIRATION_YEAR = "expirationYear";
    private static final String PAYMENT_PROVIDER = "paymentProvider";
    private static final String CARD_NUMBER = "cardNumber";
    private static final String CARD_TYPE = "cardType";
    private static final String EMAIL = "email";
    private static final String CARDHOLDER_NAME = "cardholderName";
    private static final String INTENT = "intent";
    private static final String AMOUNT = "amount";
    private static final String FUNDING = "funding";
    @Mock
    private BrainTreeSubscriptionInfoData source;

    @InjectMocks
    private BrainTreeInfoPopulator unit;

    @Test
    public void shouldPopulateBraintreeInfo() {
        final BraintreeInfo target = new BraintreeInfo();

        when(source.getPaymentMethodToken()).thenReturn(TOKEN);
        when(source.getPaymentMethodGraphQLToken()).thenReturn(GRAPH_QL_TOKEN);
        when(source.getNonce()).thenReturn(NONCE);
        when(source.getDeviceData()).thenReturn(DEVICE_DATA);
        when(source.getImageSource()).thenReturn(IMAGE_SOURCE);
        when(source.getExpirationMonth()).thenReturn(EXPIRATION_MONTH);
        when(source.getExpirationYear()).thenReturn(EXPIRATION_YEAR);
        when(source.getLiabilityShifted()).thenReturn(true);
        when(source.getPaymentProvider()).thenReturn(PAYMENT_PROVIDER);
        when(source.isSavePaymentInfo()).thenReturn(true);
        when(source.isShouldBeSaved()).thenReturn(true);
        when(source.getCardNumber()).thenReturn(CARD_NUMBER);
        when(source.getCardType()).thenReturn(CARD_TYPE);
        when(source.getEmail()).thenReturn(EMAIL);
        when(source.getCardholder()).thenReturn(CARDHOLDER_NAME);
        when(source.getIntent()).thenReturn(INTENT);
        when(source.getAmount()).thenReturn(AMOUNT);
        when(source.getPaypalFundingSource()).thenReturn(FUNDING);

        unit.populate(source, target);

        assertEquals(TOKEN, target.getPaymentMethodToken());
        assertEquals(GRAPH_QL_TOKEN, target.getPaymentMethodGraphQLToken());
        assertEquals(NONCE, target.getNonce());
        assertEquals(DEVICE_DATA, target.getDeviceData());
        assertEquals(IMAGE_SOURCE, target.getImageSource());
        assertEquals(EXPIRATION_MONTH, target.getExpirationMonth());
        assertEquals(EXPIRATION_YEAR, target.getExpirationYear());
        assertTrue(target.getLiabilityShifted());
        assertEquals(PAYMENT_PROVIDER, target.getPaymentProvider());
        assertTrue(target.isSavePaymentInfo());
        assertTrue(target.isShouldBeSaved());
        assertEquals(CARD_NUMBER, target.getCardNumber());
        assertEquals(CARD_TYPE, target.getCardType());
        assertEquals(EMAIL, target.getEmail());
        assertEquals(CARDHOLDER_NAME, target.getCardholderName());
        assertEquals(INTENT, target.getIntent());
        assertEquals(AMOUNT, target.getAmount());
        assertEquals(FUNDING, target.getPaypalFundingSource());
    }
}
