package com.braintree.converters.populators.configuration;

import com.braintree.enums.BraintreePaymentMethodLimit;
import com.braintree.enums.BraintreePaymentMethodLimitData;
import com.braintree.hybris.data.BraintreeHostedFieldsConfigurationData;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.model.BraintreeHostedFieldsConfigurationModel;
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 BraintreeHostedFieldsConfigurationPopulatorTest {

    private static final Integer EXPIRE_BETWEEN = 1;

    @Mock
    private BraintreeHostedFieldsConfigurationModel model;
    @InjectMocks
    private BraintreeHostedFieldsConfigurationPopulator unit;

    @Test
    public void shouldPopulateHostedFieldsConfiguration() {
        BraintreeHostedFieldsConfigurationData data = new BraintreeHostedFieldsConfigurationData();

        when(model.isEnabled()).thenReturn(true);
        when(model.isReverify()).thenReturn(true);
        when(model.isVerifyCard()).thenReturn(true);
        when(model.getExpireBetween()).thenReturn(EXPIRE_BETWEEN);
        when(model.isExpireOnAdding()).thenReturn(true);
        when(model.getSavedCardAccountLimit()).thenReturn(BraintreePaymentMethodLimit.ONE);

        unit.populate(model, data);

        assertTrue(data.isEnabled());
        assertTrue(data.isReverify());
        assertTrue(data.isVerifyCard());
        assertEquals(EXPIRE_BETWEEN, data.getExpireBetween());
        assertTrue(data.isExpireOnAdding());
        assertEquals(BraintreePaymentMethodLimitData.ONE, data.getSavedCardAccountLimit());
    }
}