package com.braintree.commands.impl;

import com.braintreegateway.ValidationError;
import com.braintreegateway.ValidationErrorCode;
import de.hybris.bootstrap.annotations.UnitTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.Mock;

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

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

    public static final String EXPECTED_CODE = "Please enter a valid credit card number.";
    public static final String ERROR_MESSAGE = "error";
    public static final String ERROR_NOT_KNOWN_CODE_MESSAGE = "error(ADDRESS_COMPANY_IS_INVALID)";

    @Mock
    private ValidationError mockError;
    @InjectMocks
    private DefaultBraintreeErrorTranslator defaultBraintreeErrorTranslator;

    @Test
    public void testGetMessageWithMappedErrorCode() {
        when(mockError.getCode()).thenReturn(ValidationErrorCode.ADDRESS_POSTAL_CODE_INVALID_CHARACTERS);
        when(mockError.getMessage()).thenReturn(ERROR_MESSAGE);

        String result = defaultBraintreeErrorTranslator.getMessage(mockError);

        assertEquals(EXPECTED_CODE, result);
    }

    @Test
    public void testGetMessageWithNoKnownErrorCode() {
        when(mockError.getCode()).thenReturn(ValidationErrorCode.ADDRESS_COMPANY_IS_INVALID);
        when(mockError.getMessage()).thenReturn(ERROR_MESSAGE);

        String result = defaultBraintreeErrorTranslator.getMessage(mockError);

        assertEquals(ERROR_NOT_KNOWN_CODE_MESSAGE, result);
    }
}
