/**
 *
 */
package com.braintree.payment.validators;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.commercefacades.user.data.AddressData;
import de.hybris.platform.commercefacades.user.data.CountryData;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.validation.BindingResult;

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

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

    private static final int EXCEPTED_ERROR_NUMBER = 6;
    private static final String US = "US";
    private static final String FIRST_NAME = "FirstName";
    private static final String LAST_NAME = "LastName";
    private static final String LINE_1 = "Line1";
    private static final String TOWN = "Town";
    private static final String POSTAL_CODE = "PostalCode";

    @Mock
    private AddressData addressData;
    @Mock
    private CountryData countryData;
    @Mock
    private BindingResult bindingResult;

    @InjectMocks
    private BrainTreePaymentDetailsValidator unit;

    @Test
    public void validatePaymentDetailsShouldReturnExceptedNumberOfErrors() {
        when(addressData.getCountry()).thenReturn(countryData);

        unit.validatePaymentDetails(addressData, bindingResult);
        assertEquals(EXCEPTED_ERROR_NUMBER, unit.validatePaymentDetails(addressData, bindingResult).size());
    }

    @Test
    public void validatePaymentDetailsShouldReturnNoErrors(){
        when(addressData.getCountry()).thenReturn(countryData);
        when(countryData.getIsocode()).thenReturn(US);
        when(addressData.getFirstName()).thenReturn(FIRST_NAME);
        when(addressData.getLastName()).thenReturn(LAST_NAME);
        when(addressData.getLine1()).thenReturn(LINE_1);
        when(addressData.getTown()).thenReturn(TOWN);
        when(addressData.getPostalCode()).thenReturn(POSTAL_CODE);

        assertEquals(0, unit.validatePaymentDetails(addressData, bindingResult).size());
    }
}
