package com.braintree.populators;

import com.braintree.command.result.BrainTreePaymentDetailsResult;
import com.braintreegateway.UsBankAccount;
import de.hybris.bootstrap.annotations.UnitTest;
import org.apache.commons.lang.StringUtils;
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 static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

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

    private static final String TOKEN = "token";
    private static final String ROUTING_NUMBER = "routingNumber";
    private static final String LAST_FOR_NUMBERS = "1234";
    private static final String IMAGE_URL = "imageUrl";
    private static final String PAYMENT_PROVIDER = "UsBankAccount";

    @InjectMocks
    private BrainTreeUsBankAccountPaymentMethodToPaymentDetailsPopulator unit;

    @Mock
    private UsBankAccount usBankAccount;

    @Before
    public void setUp() {
        when(usBankAccount.getToken()).thenReturn(TOKEN);
        when(usBankAccount.getRoutingNumber()).thenReturn(ROUTING_NUMBER);
        when(usBankAccount.isVerified()).thenReturn(Boolean.TRUE);
        when(usBankAccount.getLast4()).thenReturn(LAST_FOR_NUMBERS);
        when(usBankAccount.getImageUrl()).thenReturn(IMAGE_URL);
    }

    @Test
    public void shouldPopulateBrainTreeUsBankAccountPaymentMethodToPaymentDetails() {
        BrainTreePaymentDetailsResult brainTreePaymentDetailsResult = new BrainTreePaymentDetailsResult();

        unit.populate(usBankAccount, brainTreePaymentDetailsResult);

        assertEquals(TOKEN, brainTreePaymentDetailsResult.getPaymentMethodToken());
        assertEquals(ROUTING_NUMBER, brainTreePaymentDetailsResult.getRoutingNumber());
        assertEquals(Boolean.TRUE, brainTreePaymentDetailsResult.getVerified());
        assertEquals(PAYMENT_PROVIDER, brainTreePaymentDetailsResult.getPaymentProvider());
        assertEquals(LAST_FOR_NUMBERS, brainTreePaymentDetailsResult.getLast4());
        assertEquals(IMAGE_URL, brainTreePaymentDetailsResult.getImageUrl());
        assertEquals(StringUtils.EMPTY, brainTreePaymentDetailsResult.getCardType());
        assertEquals(StringUtils.EMPTY, brainTreePaymentDetailsResult.getExpirationMonth());
        assertEquals(StringUtils.EMPTY, brainTreePaymentDetailsResult.getExpirationYear());
        assertEquals(StringUtils.EMPTY, brainTreePaymentDetailsResult.getCardNumber());
        assertEquals(StringUtils.EMPTY, brainTreePaymentDetailsResult.getCardholderName());
    }
}
