package com.braintree.customersupportbackoffice.renderers;

import com.braintree.customersupportbackoffice.constants.BraintreeCustomerSupportBackofficeConstants.Style;
import com.braintree.customersupportbackoffice.constants.BraintreeCustomerSupportBackofficeConstants.Text;
import com.braintree.customersupportbackoffice.facade.BraintreeCheckConnectionFacade;
import com.hybris.cockpitng.core.config.impl.jaxb.editorarea.AbstractPanel;
import com.hybris.cockpitng.dataaccess.facades.type.DataType;
import com.hybris.cockpitng.engine.WidgetInstanceManager;
import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.core.model.BraintreeACHConfigurationModel;
import de.hybris.platform.core.model.BraintreeApplePayConfigurationModel;
import de.hybris.platform.core.model.BraintreeConnectWithPayPalConfigurationModel;
import de.hybris.platform.core.model.BraintreeGeneralConfigurationModel;
import de.hybris.platform.core.model.BraintreeGooglePayConfigurationModel;
import de.hybris.platform.core.model.BraintreeHostedFieldsConfigurationModel;
import de.hybris.platform.core.model.BraintreeLocalPaymentsConfigurationModel;
import de.hybris.platform.core.model.BraintreePayPalConfigurationModel;
import de.hybris.platform.core.model.BraintreePluginConfigurationModel;
import de.hybris.platform.core.model.BraintreeSRCConfigurationModel;
import de.hybris.platform.core.model.BraintreeVenmoConfigurationModel;
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.zkoss.zk.ui.Component;
import org.zkoss.zul.Button;
import org.zkoss.zul.Div;
import org.zkoss.zul.Html;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;


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

    private static final String SUCCESS = "Success";
    private static final String FAIL = "Fail";
    private static final String REFRESH_BUTTON = "Refresh_button";
    private static final String ESSENTIAL_CONFIG_CHECK = "ESSENTIAL_CONFIG_CHECK";
    private static final String MERCHANT_ID = "MERCHANT_ID";
    private static final String PUBLICK_KEY = "PUBLICK_KEY";
    private static final String PRIVATE_KEY = "PRIVATE_KEY";
    private static final String ENVIROMENT_TYPE = "ENVIROMENT_TYPE";
    private static final String CONNECT_WITH_BRAINTREE = "CONNECT_WITH_BRAINTREE";
    private static final String ENABLE = "ENABLE";
    private static final String BASE_STORE_NAME = "BASE_STORE_NAME";
    private static final String PLUGIN_CONFIGURATION_CHECK = "PLUGIN_CONFIGURATION_CHECK";
    private static final String PAYPAL_CONFIGURATION_CHECK = "PAYPAL_CONFIGURATION_CHECK";

    @Mock
    private Div div;
    @Mock
    private Component component;
    @Mock
    private BraintreePluginConfigurationModel pluginConfiguration;

    @Mock
    private BraintreeCheckConnectionFacade checkConnectionFacade;

    @Spy
    @InjectMocks
    private BraintreeCheckConnectionRenderer unit;

    @Test
    public void shouldRender() {
        final AbstractPanel abstractPanel = mock(AbstractPanel.class);
        final BraintreePluginConfigurationModel braintreePluginConfigurationModel = mock(BraintreePluginConfigurationModel.class);
        final DataType dataType = mock(DataType.class);
        final WidgetInstanceManager widgetInstanceManager = mock(WidgetInstanceManager.class);

        doReturn(div).when(unit).getMainDiv(component, braintreePluginConfigurationModel);

        unit.render(component, abstractPanel, braintreePluginConfigurationModel, dataType, widgetInstanceManager);

        verify(unit).getMainDiv(component, braintreePluginConfigurationModel);
    }

    @Test
    public void shouldGetMainDivWithoutPayPalConfiguration() {
        final Div refreshButtonDiv = mock(Div.class);
        final Div connectWithBraintreeSetupDiv = mock(Div.class);
        final Div pluginConfigurationCheckSetupDiv = mock(Div.class);
        final BraintreeConnectWithPayPalConfigurationModel connectWithPayPal = mock(BraintreeConnectWithPayPalConfigurationModel.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(refreshButtonDiv).when(unit).getRefreshButton(component, pluginConfiguration);
        doReturn(connectWithBraintreeSetupDiv).when(unit).getConnectWithBraintreeSetupDiv();
        doReturn(pluginConfigurationCheckSetupDiv).when(unit).getPluginConfigurationCheckSetupDiv(pluginConfiguration);
        when(pluginConfiguration.getBraintreeConnectWithPayPalConfiguration()).thenReturn(connectWithPayPal);
        when(connectWithPayPal.isEnable()).thenReturn(false);

        assertEquals(div, unit.getMainDiv(component, pluginConfiguration));

        verify(unit).getNewDiv();
        verify(unit).getRefreshButton(component, pluginConfiguration);
        verify(div).appendChild(refreshButtonDiv);
        verify(unit).getConnectWithBraintreeSetupDiv();
        verify(div).appendChild(connectWithBraintreeSetupDiv);
        verify(unit).getPluginConfigurationCheckSetupDiv(pluginConfiguration);
        verify(div).appendChild(pluginConfigurationCheckSetupDiv);
        verify(pluginConfiguration).getBraintreeConnectWithPayPalConfiguration();
        verify(connectWithPayPal).isEnable();
    }

    @Test
    public void shouldGetMainDivWithPayPalConfiguration() {
        final Div refreshButtonDiv = mock(Div.class);
        final Div connectWithBraintreeSetupDiv = mock(Div.class);
        final Div pluginConfigurationCheckSetupDiv = mock(Div.class);
        final BraintreeConnectWithPayPalConfigurationModel connectWithPayPal = mock(BraintreeConnectWithPayPalConfigurationModel.class);
        final Div paypalConfigurationCheckDiv = mock(Div.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(refreshButtonDiv).when(unit).getRefreshButton(component, pluginConfiguration);
        doReturn(connectWithBraintreeSetupDiv).when(unit).getConnectWithBraintreeSetupDiv();
        doReturn(pluginConfigurationCheckSetupDiv).when(unit).getPluginConfigurationCheckSetupDiv(pluginConfiguration);
        when(pluginConfiguration.getBraintreeConnectWithPayPalConfiguration()).thenReturn(connectWithPayPal);
        when(connectWithPayPal.isEnable()).thenReturn(true);
        doReturn(paypalConfigurationCheckDiv).when(unit).getPaypalConfigurationCheckDiv();

        assertEquals(div, unit.getMainDiv(component, pluginConfiguration));

        verify(unit).getNewDiv();
        verify(unit).getRefreshButton(component, pluginConfiguration);
        verify(div).appendChild(refreshButtonDiv);
        verify(unit).getConnectWithBraintreeSetupDiv();
        verify(div).appendChild(connectWithBraintreeSetupDiv);
        verify(unit).getPluginConfigurationCheckSetupDiv(pluginConfiguration);
        verify(div).appendChild(pluginConfigurationCheckSetupDiv);
        verify(pluginConfiguration).getBraintreeConnectWithPayPalConfiguration();
        verify(connectWithPayPal).isEnable();
        verify(unit).getPaypalConfigurationCheckDiv();
    }

    @Test
    public void shouldGetRefreshButton() {
        final Button button = mock(Button.class);

        doReturn(REFRESH_BUTTON).when(unit).getLabel(Text.REFRESH_BUTTON);
        doReturn(button).when(unit).getNewButton(REFRESH_BUTTON);
        doReturn(div).when(unit).getNewDiv();

        assertEquals(div, unit.getRefreshButton(component, pluginConfiguration));

        verify(div).appendChild(button);
        verify(div).setStyle(Style.REFRESH_BUTTON);
    }

    @Test
    public void shouldGetConnectWithBraintreeSetupDiv() {
        final Html html = mock(Html.class);
        final Div merchantIdDiv = mock(Div.class);
        final Div publicKeyDiv = mock(Div.class);
        final Div privateKeyDiv = mock(Div.class);
        final Div environmentDiv = mock(Div.class);
        final Div pingDiv = mock(Div.class);

        doReturn(div).when(unit).getNewDiv();

        doReturn(ESSENTIAL_CONFIG_CHECK).when(unit).getLabel(Text.ESSENTIAL_CONFIG_CHECK);
        doReturn(html).when(unit).getNewHtml("1. " + ESSENTIAL_CONFIG_CHECK);

        when(checkConnectionFacade.isMerchantIDPresented()).thenReturn(true);
        doReturn(merchantIdDiv).when(unit).getResultDiv(Text.BRAINTREE_MERCHANT_ID, Text.SUCCESS);

        when(checkConnectionFacade.isPublicKeyPresented()).thenReturn(true);
        doReturn(publicKeyDiv).when(unit).getResultDiv(Text.BRAINTREE_PUBLICK_KEY, Text.SUCCESS);

        when(checkConnectionFacade.isPrivateKeyPresented()).thenReturn(true);
        doReturn(privateKeyDiv).when(unit).getResultDiv(Text.BRAINTREE_PRIVATE_KEY, Text.SUCCESS);

        when(checkConnectionFacade.isEnvironmentPresented()).thenReturn(true);
        doReturn(environmentDiv).when(unit).getResultDiv(Text.BRAINTREE_ENVIROMENT_TYPE, Text.SUCCESS);

        when(checkConnectionFacade.canCheckConnectWithBraintree()).thenReturn(true);
        when(checkConnectionFacade.isBraintreePingPresented()).thenReturn(true);
        doReturn(pingDiv).when(unit).getResultDiv(Text.CONNECT_WITH_BRAINTREE, Text.SUCCESS);

        assertEquals(div, unit.getConnectWithBraintreeSetupDiv());

        verify(div).appendChild(html);
        verify(div).appendChild(merchantIdDiv);
        verify(div).appendChild(publicKeyDiv);
        verify(div).appendChild(privateKeyDiv);
        verify(div).appendChild(environmentDiv);
        verify(checkConnectionFacade).canCheckConnectWithBraintree();
        verify(div).appendChild(pingDiv);
    }

    @Test
    public void shouldGetPluginConfigurationCheckSetupDiv() {
        final Html html = mock(Html.class);
        doReturn(div).when(unit).getNewDiv();
        doReturn(PLUGIN_CONFIGURATION_CHECK).when(unit).getLabel(Text.PLUGIN_CONFIGURATION_CHECK);
        doReturn(html).when(unit).getNewHtml("2. " + PLUGIN_CONFIGURATION_CHECK);

        final Div usageDiv = mock(Div.class);
        doReturn(usageDiv).when(unit).getResultDiv(Text.CONFIGURATION_USAGE, null);
        doNothing().when(unit).getConfigurationUsageChildSetupDiv(pluginConfiguration, div);

        final Div generalDiv = mock(Div.class);
        final BraintreeGeneralConfigurationModel generalConfigurationModel = mock(BraintreeGeneralConfigurationModel.class);
        final Map<String, String> map = mock(HashMap.class);
        final Div merchantAccountIdDiv = mock(Div.class);
        doReturn(generalDiv).when(unit).getResultDiv(Text.GENERAL, null);
        when(pluginConfiguration.getBraintreeGeneralConfiguration()).thenReturn(generalConfigurationModel);
        when(generalConfigurationModel.getMerchantAccountId()).thenReturn(map);
        when(map.isEmpty()).thenReturn(false);
        doReturn(merchantAccountIdDiv).when(unit).getChildResultDiv(Text.MERCHANT_ACCOUNT_ID, Text.TRUE);

        final BraintreeConnectWithPayPalConfigurationModel connectWithPayPalConfigurationModel = mock(BraintreeConnectWithPayPalConfigurationModel.class);
        final Div connectDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreeConnectWithPayPalConfiguration()).thenReturn(connectWithPayPalConfigurationModel);
        doReturn(connectDiv).when(unit).getResultDiv(Text.CONNECT_WITH_PAYPAL, null);
        when(connectWithPayPalConfigurationModel.isEnable()).thenReturn(true);

        final BraintreePayPalConfigurationModel payPalConfigurationModel = mock(BraintreePayPalConfigurationModel.class);
        final Div payPalDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreePayPalConfiguration()).thenReturn(payPalConfigurationModel);
        doReturn(payPalDiv).when(unit).getResultDiv(Text.PAYPAL, Text.PRESENT);
        when(payPalConfigurationModel.isPayPalEnabled()).thenReturn(true);

        final BraintreeVenmoConfigurationModel venmoConfigurationModel = mock(BraintreeVenmoConfigurationModel.class);
        final Div venmoDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreeVenmoConfiguration()).thenReturn(venmoConfigurationModel);
        doReturn(venmoDiv).when(unit).getResultDiv(Text.VENMO, Text.PRESENT);
        when(venmoConfigurationModel.isEnabled()).thenReturn(true);

        final BraintreeLocalPaymentsConfigurationModel localPaymentsConfigurationModel = mock(BraintreeLocalPaymentsConfigurationModel.class);
        final Div lpmDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreeLocalPaymentsConfiguration()).thenReturn(localPaymentsConfigurationModel);
        doReturn(lpmDiv).when(unit).getResultDiv(Text.LPM, Text.PRESENT);
        when(localPaymentsConfigurationModel.isEnabled()).thenReturn(true);

        final BraintreeHostedFieldsConfigurationModel hostedFieldsConfigurationModel = mock(BraintreeHostedFieldsConfigurationModel.class);
        final Div hostedFieldsDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreeHostedFieldsConfiguration()).thenReturn(hostedFieldsConfigurationModel);
        doReturn(hostedFieldsDiv).when(unit).getResultDiv(Text.HOSTED_FIELDS, Text.PRESENT);
        when(hostedFieldsConfigurationModel.isEnabled()).thenReturn(true);

        final BraintreeApplePayConfigurationModel applePayConfigurationModel = mock(BraintreeApplePayConfigurationModel.class);
        final Div applePayDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreeApplePayConfiguration()).thenReturn(applePayConfigurationModel);
        doReturn(applePayDiv).when(unit).getResultDiv(Text.APPLE_PAY, Text.PRESENT);
        when(applePayConfigurationModel.isEnabled()).thenReturn(true);

        final BraintreeGooglePayConfigurationModel googlePayConfigurationModel = mock(BraintreeGooglePayConfigurationModel.class);
        final Div googlePayDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreeGooglePayConfiguration()).thenReturn(googlePayConfigurationModel);
        doReturn(googlePayDiv).when(unit).getResultDiv(Text.GOOGLE_PAY, Text.PRESENT);
        when(googlePayConfigurationModel.isEnabled()).thenReturn(true);

        final BraintreeSRCConfigurationModel srcConfigurationModel = mock(BraintreeSRCConfigurationModel.class);
        final Div srcDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreeSRCConfiguration()).thenReturn(srcConfigurationModel);
        doReturn(srcDiv).when(unit).getResultDiv(Text.SRC, Text.PRESENT);
        when(srcConfigurationModel.isEnabled()).thenReturn(true);

        final BraintreeACHConfigurationModel achConfigurationModel = mock(BraintreeACHConfigurationModel.class);
        final Div achDiv = mock(Div.class);
        when(pluginConfiguration.getBraintreeACHConfiguration()).thenReturn(achConfigurationModel);
        doReturn(achDiv).when(unit).getResultDiv(Text.ACH, Text.PRESENT);
        when(achConfigurationModel.isEnabled()).thenReturn(true);

        final Div enableDiv = mock(Div.class);
        doReturn(enableDiv).when(unit).getChildResultDiv(Text.ENABLE, Text.TRUE);

        final Div result = unit.getPluginConfigurationCheckSetupDiv(pluginConfiguration);

        assertEquals(div, result);

        verify(unit).getNewDiv();
        verify(unit).getLabel(Text.PLUGIN_CONFIGURATION_CHECK);
        verify(unit).getNewHtml("2. " + PLUGIN_CONFIGURATION_CHECK);

        verify(unit).getResultDiv(Text.CONFIGURATION_USAGE, null);

        verify(unit).getResultDiv(Text.GENERAL, null);
        verify(pluginConfiguration).getBraintreeGeneralConfiguration();
        verify(generalConfigurationModel).getMerchantAccountId();
        verify(map).isEmpty();
        verify(unit).getChildResultDiv(Text.MERCHANT_ACCOUNT_ID, Text.TRUE);

        verify(pluginConfiguration).getBraintreeConnectWithPayPalConfiguration();
        verify(unit).getResultDiv(Text.CONNECT_WITH_PAYPAL, null);
        verify(connectWithPayPalConfigurationModel).isEnable();

        verify(pluginConfiguration, times(3)).getBraintreePayPalConfiguration();
        verify(unit).getResultDiv(Text.PAYPAL, Text.PRESENT);
        verify(payPalConfigurationModel).isPayPalEnabled();

        verify(pluginConfiguration, times(3)).getBraintreeVenmoConfiguration();
        verify(unit).getResultDiv(Text.VENMO, Text.PRESENT);
        verify(venmoConfigurationModel).isEnabled();

        verify(pluginConfiguration, times(3)).getBraintreeLocalPaymentsConfiguration();
        verify(unit).getResultDiv(Text.LPM, Text.PRESENT);
        verify(localPaymentsConfigurationModel).isEnabled();

        verify(pluginConfiguration, times(3)).getBraintreeHostedFieldsConfiguration();
        verify(unit).getResultDiv(Text.HOSTED_FIELDS, Text.PRESENT);
        verify(hostedFieldsConfigurationModel).isEnabled();

        verify(pluginConfiguration, times(3)).getBraintreeApplePayConfiguration();
        verify(unit).getResultDiv(Text.APPLE_PAY, Text.PRESENT);
        verify(applePayConfigurationModel).isEnabled();

        verify(pluginConfiguration, times(3)).getBraintreeGooglePayConfiguration();
        verify(unit).getResultDiv(Text.GOOGLE_PAY, Text.PRESENT);
        verify(googlePayConfigurationModel).isEnabled();

        verify(pluginConfiguration, times(3)).getBraintreeSRCConfiguration();
        verify(unit).getResultDiv(Text.SRC, Text.PRESENT);
        verify(srcConfigurationModel).isEnabled();

        verify(pluginConfiguration, times(3)).getBraintreeACHConfiguration();
        verify(unit).getResultDiv(Text.ACH, Text.PRESENT);
        verify(achConfigurationModel).isEnabled();

        verify(unit, times(9)).getChildResultDiv(Text.ENABLE, Text.TRUE);
    }

    @Test
    public void shouldGetPaypalConfigurationCheckDivWithoutCheckConnectWithPayPal() {
        final Html html = mock(Html.class);
        final Div clientIdDiv= mock(Div.class);
        final Div secretKeyDiv= mock(Div.class);

        doReturn(div).when(unit).getNewDiv();

        doReturn(PAYPAL_CONFIGURATION_CHECK).when(unit).getLabel(Text.PAYPAL_CONFIGURATION_CHECK);
        doReturn(html).when(unit).getNewHtml("3. " + PAYPAL_CONFIGURATION_CHECK);

        when(checkConnectionFacade.isPayPalClientIdPresented()).thenReturn(true);
        doReturn(clientIdDiv).when(unit).getResultDiv(Text.PAYPAL_CLIENT_ID, Text.SUCCESS);

        when(checkConnectionFacade.isPayPalSecretKeyPresented()).thenReturn(true);
        doReturn(secretKeyDiv).when(unit).getResultDiv(Text.PAYPAL_SECRET_KEY, Text.SUCCESS);

        when(checkConnectionFacade.canCheckConnectWithPayPal()).thenReturn(false);

        final Div result = unit.getPaypalConfigurationCheckDiv();

        assertEquals(div, result);
        verify(div).setStyle(Style.BLOCK);
        verify(div).appendChild(html);
        verify(div).appendChild(clientIdDiv);
        verify(div).appendChild(secretKeyDiv);
        verify(checkConnectionFacade).canCheckConnectWithPayPal();
    }

    @Test
    public void shouldGetPaypalConfigurationCheckDivWithCheckConnectWithPayPal() {
        final Html html = mock(Html.class);
        final Div clientIdDiv = mock(Div.class);
        final Div secretKeyDiv = mock(Div.class);
        final Div canEstablishDiv = mock(Div.class);

        doReturn(div).when(unit).getNewDiv();

        doReturn(PAYPAL_CONFIGURATION_CHECK).when(unit).getLabel(Text.PAYPAL_CONFIGURATION_CHECK);
        doReturn(html).when(unit).getNewHtml("3. " + PAYPAL_CONFIGURATION_CHECK);

        when(checkConnectionFacade.isPayPalClientIdPresented()).thenReturn(true);
        doReturn(clientIdDiv).when(unit).getResultDiv(Text.PAYPAL_CLIENT_ID, Text.SUCCESS);

        when(checkConnectionFacade.isPayPalSecretKeyPresented()).thenReturn(true);
        doReturn(secretKeyDiv).when(unit).getResultDiv(Text.PAYPAL_SECRET_KEY, Text.SUCCESS);

        when(checkConnectionFacade.canCheckConnectWithPayPal()).thenReturn(true);
        when(checkConnectionFacade.canEstablishConnectWithPayPal()).thenReturn(true);
        doReturn(canEstablishDiv).when(unit).getResultDiv(Text.CONNECT_WITH_PAYPAL, Text.SUCCESS);

        final Div result = unit.getPaypalConfigurationCheckDiv();

        assertEquals(div, result);
        verify(div).setStyle(Style.BLOCK);
        verify(div).appendChild(html);
        verify(div).appendChild(clientIdDiv);
        verify(div).appendChild(secretKeyDiv);
        verify(checkConnectionFacade).canCheckConnectWithPayPal();
        verify(div).appendChild(canEstablishDiv);
    }

    @Test
    public void shouldGetConfigurationUsageChildSetupDivWithBaseStore() {
        final Div baseStoreNameDiv = mock(Div.class);

        when(checkConnectionFacade.getBaseStoreNames(pluginConfiguration)).thenReturn(Arrays.asList(BASE_STORE_NAME));
        doReturn(baseStoreNameDiv).when(unit).getBaseStoreNameDiv(BASE_STORE_NAME);

        unit.getConfigurationUsageChildSetupDiv(pluginConfiguration, div);

        verify(checkConnectionFacade).getBaseStoreNames(pluginConfiguration);
        verify(unit).getBaseStoreNameDiv(BASE_STORE_NAME);
    }

    @Test
    public void shouldGetConfigurationUsageChildSetupDivWithoutBaseStore() {
        final Div childResultDiv = mock(Div.class);
        final Div childValueDiv = mock(Div.class);

        when(checkConnectionFacade.getBaseStoreNames(pluginConfiguration)).thenReturn(Arrays.asList());
        doReturn(childResultDiv).when(unit).getChildResultDiv(Text.NON_USE_THIS_CONFIGURATION, null);
        when(childResultDiv.getChildren()).thenReturn(Arrays.asList(childValueDiv));

        unit.getConfigurationUsageChildSetupDiv(pluginConfiguration, div);

        verify(checkConnectionFacade).getBaseStoreNames(pluginConfiguration);
        verify(unit).getChildResultDiv(Text.NON_USE_THIS_CONFIGURATION, null);
        verify(childResultDiv).getChildren();
        verify(childValueDiv).setStyle(Style.NON_USE_THIS_CONFIGURATION);
        verify(div).appendChild(childResultDiv);
    }

    @Test
    public void shouldGetBaseStoreNameDiv() {
        final Div valueDiv = mock(Div.class);
        final Html html = mock(Html.class);

        doReturn(html).when(unit).getNewHtml("&#x2022; " + BASE_STORE_NAME);
        doReturn(div).when(unit).getNewDiv();

        assertEquals(div, unit.getBaseStoreNameDiv(BASE_STORE_NAME));

        verify(unit, times(2)).getNewDiv();
        verify(unit).getNewHtml("&#x2022; " + BASE_STORE_NAME);
    }

    @Test
    public void shouldGetChildResultDivWithStatus() {
        final Div valueDiv = mock(Div.class);
        final Div statusDiv = mock(Div.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(valueDiv).when(unit).getValueDiv(MERCHANT_ID, true);
        doReturn(statusDiv).when(unit).getStatusDiv(Text.TRUE);

        assertEquals(div, unit.getChildResultDiv(MERCHANT_ID, Text.TRUE));

        verify(div).appendChild(valueDiv);
        verify(div).appendChild(statusDiv);
        verify(div).setStyle(Style.RESULT);
    }

    @Test
    public void shouldGetChildResultDivWithoutStatus() {
        final Div valueDiv = mock(Div.class);
        final Div statusDiv = mock(Div.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(valueDiv).when(unit).getValueDiv(MERCHANT_ID, true);

        assertEquals(div, unit.getChildResultDiv(MERCHANT_ID, null));

        verify(div).appendChild(valueDiv);
        verify(div, never()).appendChild(statusDiv);
        verify(div).setStyle(Style.RESULT);
    }

    @Test
    public void shouldGetResultDivWithStatus() {
        final Div valueDiv = mock(Div.class);
        final Div statusDiv = mock(Div.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(valueDiv).when(unit).getValueDiv(MERCHANT_ID, false);
        doReturn(statusDiv).when(unit).getStatusDiv(Text.SUCCESS);

        assertEquals(div, unit.getResultDiv(MERCHANT_ID, Text.SUCCESS));

        verify(div).appendChild(valueDiv);
        verify(div).appendChild(statusDiv);
        verify(div).setStyle(Style.RESULT);
    }

    @Test
    public void shouldGetResultDivWithoutStatus() {
        final Div valueDiv = mock(Div.class);
        final Div statusDiv = mock(Div.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(valueDiv).when(unit).getValueDiv(MERCHANT_ID, false);

        assertEquals(div, unit.getResultDiv(MERCHANT_ID, null));

        verify(div).appendChild(valueDiv);
        verify(div, never()).appendChild(statusDiv);
        verify(div).setStyle(Style.RESULT);
    }

    @Test
    public void shouldGetValueDiv() {
        final Html html = mock(Html.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(MERCHANT_ID).when(unit).getLabel(Text.BRAINTREE_MERCHANT_ID);
        doReturn(html).when(unit).getNewHtml("&#x2022; " + MERCHANT_ID);

        assertEquals(div, unit.getValueDiv(Text.BRAINTREE_MERCHANT_ID, false));

        verify(unit).getLabel(Text.BRAINTREE_MERCHANT_ID);
        verify(div).appendChild(html);
        verify(div).setStyle(Style.RESULT_VALUE);
    }

    @Test
    public void shouldGetChildValueDiv() {
        final Html html = mock(Html.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(MERCHANT_ID).when(unit).getLabel(Text.BRAINTREE_MERCHANT_ID);
        doReturn(html).when(unit).getNewHtml("&#x2022; " + MERCHANT_ID);

        assertEquals(div, unit.getValueDiv(Text.BRAINTREE_MERCHANT_ID, true));

        verify(unit).getLabel(Text.BRAINTREE_MERCHANT_ID);
        verify(div).appendChild(html);
        verify(div).setStyle(Style.CHILD_RESULT_VALUE);
    }

    @Test
    public void shouldGetSuccessStatusDiv() {
        final Html html = mock(Html.class);

        doReturn(div).when(unit).getNewDiv();
        doReturn(SUCCESS).when(unit).getLabel(Text.SUCCESS);
        doReturn(html).when(unit).getNewHtml(SUCCESS);
        doReturn(Style.RESULT_STATUS_SUCCESS).when(unit).getStyle(Text.SUCCESS);

        assertEquals(div, unit.getStatusDiv(Text.SUCCESS));

        verify(div).appendChild(html);
        verify(div).setStyle(Style.RESULT_STATUS_SUCCESS);
    }

    @Test
    public void shouldGetStyleForSuccessStatus() {
        String result = unit.getStyle(Text.SUCCESS);
        assertEquals(Style.RESULT_STATUS_SUCCESS, result);
    }

    @Test
    public void shouldGetStyleForTrueStatus() {
        String result = unit.getStyle(Text.TRUE);
        assertEquals(Style.RESULT_STATUS_SUCCESS, result);
    }

    @Test
    public void shouldGetStyleForFailStatus() {
        String result = unit.getStyle(Text.FAIL);
        assertEquals(Style.RESULT_STATUS_FAIL, result);
    }

    @Test
    public void shouldGetStyleForFalseStatus() {
        String result = unit.getStyle(Text.FALSE);
        assertEquals(Style.RESULT_STATUS_FAIL, result);
    }

    @Test
    public void shouldGetStyleForPresentStatus() {
        String result = unit.getStyle(Text.PRESENT);
        assertEquals(Style.RESULT_STATUS, result);
    }

}
