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

import com.braintree.exceptions.BraintreeResourceErrorMessage;
import com.braintree.payment.validators.impl.DefaultBraintreeEditPaymentMethodValidator;
import de.hybris.bootstrap.annotations.UnitTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;

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


    private static final String CARD_HOLDER = "cardHolder";
    private static final String CORRECT_EXPIRATION_DATE = "02/21";
    private static final String EXPIRATION_DATE_WITH_INCORRECT_YEAR = "02/2011";
    private static final String INCORRECT_EXPIRATION_DATE = "02/21/12";
    private static final String CORRECT_CVV = "cvv";
    private static final String INCORRECT_CVV = "cvvvvv";
    private static final String TO_LONG_CARDHOLDER_NAME = "toloooo" +
            "ooooooooooooooooooooooooooooooooooooooooooooooooo" +
            "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" +
            "ooooooooooooooooooooooooooooooooooooooooooooooooooong";

    private static final String INVALID_CVV_MESSAGE_CODE =
        "text.account.profile.paymentCart.editPaymentMethod.invalid.cvv";

    private static final String INVALID_EXPIRATION_DATE_MESSAGE_CODE =
        "text.account.profile.paymentCart.editPaymentMethod.invalid.expirationDate";

    private static final String ABSENCE_EXPIRATION_DATE_MESSAGE_CODE =
        "text.account.profile.paymentCart.editPaymentMethod.required.expirationDate";
    private static final String PAYMENT_METHOD_INVALID_CARDHOLDER_TOO_LONG =
            "text.account.profile.paymentCart.editPaymentMethod.invalid.cardholderTooLong";
    private static final String PAYMENT_METHOD_ERROR_EXPIRATION_DATE = "text.account.profile.paymentCart.editPaymentMethod.error.expirationDate";

    public static final String TEXT_ACCOUNT_PROFILE_PAYMENT_CART_EDIT_PAYMENT_METHOD_INVALID_EXPIRATION_DATE
            = "text.account.profile.paymentCart.editPaymentMethod.invalid.expirationDate";

    @InjectMocks
    private DefaultBraintreeEditPaymentMethodValidator unit;


    @Test()
    public void testValidatorWithIncorrectCVV() {
        final BraintreeResourceErrorMessage resourceErrorMessage = unit.validate(CARD_HOLDER, CORRECT_EXPIRATION_DATE, INCORRECT_CVV);
        Assert.assertEquals(INVALID_CVV_MESSAGE_CODE, resourceErrorMessage.getMessageKey());
    }

    @Test
    public void testValidatorWithIncorrectExpirationDate() {
        final BraintreeResourceErrorMessage resourceErrorMessage = unit.validate(CARD_HOLDER, INCORRECT_EXPIRATION_DATE, CORRECT_CVV);
        Assert.assertEquals(INVALID_EXPIRATION_DATE_MESSAGE_CODE, resourceErrorMessage.getMessageKey());
    }

    @Test
    public void testValidatorWithWithoutExpirationDate() {
        final BraintreeResourceErrorMessage resourceErrorMessage = unit.validate(CARD_HOLDER, "", CORRECT_CVV);
        Assert.assertEquals(ABSENCE_EXPIRATION_DATE_MESSAGE_CODE, resourceErrorMessage.getMessageKey());
    }

    @Test
    public void testValidatorWithIncorrectExpirationDateLength() {
        final BraintreeResourceErrorMessage resourceErrorMessage = unit.validate(CARD_HOLDER, CORRECT_EXPIRATION_DATE, CORRECT_CVV);
        Assert.assertEquals(INVALID_EXPIRATION_DATE_MESSAGE_CODE, resourceErrorMessage.getMessageKey());
    }

    @Test
    public void testValidatorWithToLongCardholderNameLength() {
        final BraintreeResourceErrorMessage resourceErrorMessage = unit.validate(TO_LONG_CARDHOLDER_NAME, CORRECT_EXPIRATION_DATE, CORRECT_CVV);
        Assert.assertEquals(PAYMENT_METHOD_INVALID_CARDHOLDER_TOO_LONG, resourceErrorMessage.getMessageKey());
    }

    @Test
    public void testValidatorWithIncorrectExpirationYear() {
        final BraintreeResourceErrorMessage resourceErrorMessage = unit.validate(CARD_HOLDER, EXPIRATION_DATE_WITH_INCORRECT_YEAR, CORRECT_CVV);
        Assert.assertEquals(PAYMENT_METHOD_ERROR_EXPIRATION_DATE, resourceErrorMessage.getMessageKey());
    }

}
