package com.braintree.customersupportbackoffice.handler;


import com.hybris.cockpitng.dataaccess.facades.object.exceptions.ObjectSavingException;
import de.hybris.bootstrap.annotations.UnitTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class BrainTreePayPalStylesConfigurationValidationTranslationHandlerTest {
    private static final String TEST_OBJECT_ID = "";
    private static final BrainTreePayPalStylesConfigurationValidationTranslationHandler unit =
            new BrainTreePayPalStylesConfigurationValidationTranslationHandler();
    @Test
    public void shouldCanHandleReturnTrueWhenArgumentIsInstanceOfObjectSavingExceptionAndMessageContainsSpecifiedString() {
        final String BRAIN_TREE_PAY_PAL_STYLES_CONFIGURATION_VALIDATION_INTERCEPTOR = "BrainTreePayPalStylesConfigurationValidationInterceptor";
        Throwable throwable = new Throwable(BRAIN_TREE_PAY_PAL_STYLES_CONFIGURATION_VALIDATION_INTERCEPTOR);
        ObjectSavingException objectSavingException = new ObjectSavingException(TEST_OBJECT_ID, throwable);
        Assert.assertTrue(unit.canHandle(objectSavingException));
    }

    @Test
    public void shouldCanHandleReturnFalseWhenArgumentIsNotInstanceOfObjectSavingExceptionAndMessageContainsSpecifiedString() {
        Assert.assertFalse(unit.canHandle(null));
    }

    @Test
    public void shouldCanHandleReturnFalseWhenArgumentIsInstanceOfObjectSavingExceptionAndMessageContainsNotCorrectString() {
        final String BRAIN_TREE_PAY_PAL_STYLES_CONFIGURATION_VALIDATION_INTERCEPTOR = "not correct string";
        Throwable throwable = new Throwable(BRAIN_TREE_PAY_PAL_STYLES_CONFIGURATION_VALIDATION_INTERCEPTOR);
        ObjectSavingException objectSavingException = new ObjectSavingException(TEST_OBJECT_ID, throwable);
        Assert.assertFalse(unit.canHandle(objectSavingException));
    }

    @Test
    public void shouldToStringReturnSubstringStartedFromColonSymbol() {
        final String TEST_STRING = "string:substring";
        final String TEST_SUBSTRING = "substring";
        Throwable throwable = new Throwable(TEST_STRING);
        ObjectSavingException objectSavingException = new ObjectSavingException(TEST_OBJECT_ID, throwable);
        Assert.assertEquals(TEST_SUBSTRING, unit.toString(objectSavingException));
    }

}
