package com.braintreeocc.validators;

import de.hybris.bootstrap.annotations.UnitTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.validation.Errors;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.never;

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

    private static final String BUTTON = "MINICART";
    private static final String FAIL_BUTTON = "PAGE_NOT_EXIST";
    private static final String INCORRECT_BUTTON_TYPE = "Incorrect buttonType parameter";

    @Mock
    private Errors errors;

    @Spy
    @InjectMocks
    private BraintreeButtonTypeValidator unit;

    @Test
    public void shouldNotFailValidationWhenCorrectButton() {
        unit.validate(BUTTON, errors);

        verify(errors, never()).reject(FAIL_BUTTON, INCORRECT_BUTTON_TYPE);
    }

    @Test
    public void shouldFailValidationWhenWrongButton() {
        unit.validate(FAIL_BUTTON, errors);

        verify(errors).reject(FAIL_BUTTON, INCORRECT_BUTTON_TYPE);
    }

    @Test
    public void shouldReturnTrueIfPassedSupportedClass() {
        boolean isSupported = unit.supports(String.class);

        assertTrue(isSupported);
    }

    @Test
    public void shouldReturnFalseIfPassedUnsupportedClass() {
        boolean isSupported = unit.supports(Object.class);

        assertFalse(isSupported);
    }
}
