package com.braintree.customersupportbackoffice.widgets.braintreePluginConfiguration.exportConfiguration;

import de.hybris.bootstrap.annotations.UnitTest;
import de.hybris.platform.impex.model.ImpExMediaModel;
import de.hybris.platform.servicelayer.impex.ExportConfig;
import de.hybris.platform.servicelayer.impex.ExportResult;
import de.hybris.platform.servicelayer.impex.ExportService;
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 static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;



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

    @Mock
    private ExportService exportService;

    @Spy
    @InjectMocks
    private BraintreeExportConfigurationController configurationController;


    @Test
    public void shouldExportConfiguration() {
        ExportResult result = mock(ExportResult.class);
        ImpExMediaModel model = mock(ImpExMediaModel.class);
        ExportConfig config = mock(ExportConfig.class);

        doReturn(config).when(configurationController).createExportConfig();
        when(result.getExportedData()).thenReturn(model);
        when(exportService.exportData(config)).thenReturn(result);
        doNothing().when(configurationController).executeMediaDownload(model);

        configurationController.exportConfiguration();

        verify(configurationController).createExportConfig();
        verify(configurationController).executeMediaDownload(model);
        verify(result).getExportedData();
        verify(exportService).exportData(config);
    }
}
