Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.7 kB
3
Indexable
Never
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.EnumSet;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class SaleOrderShareReportComponentTest {

    @InjectMocks
    private SaleOrderShareReportComponent component;

    @Mock
    private SaleOrderShareReportRepository orderShareReportRepository;

    @Mock
    private OrderReport orderReport;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testCreatePurchaseOrderShareReportWithV1Type() {
        when(orderReport.getType()).thenReturn(EnumTypeOrderReport.V1);

        component.createPurchaseOrderShareReport(orderReport, "ticket");

        verify(orderShareReportRepository).save(Mockito.any(SaleOrderShareReportEntity.class));
    }

    @Test
    public void testCreatePurchaseOrderShareReportWithV2Type() {
        when(orderReport.getType()).thenReturn(EnumTypeOrderReport.V2);

        component.createPurchaseOrderShareReport(orderReport, "ticket");

        verify(orderShareReportRepository).save(Mockito.any(SaleOrderShareReportEntity.class));
    }

}




    @Test
    public void testGetParams() {
        String id = "d1b18c7f-6c46-4f24-9c35-9d9bf849b8fa";

        List<ProductFile> productFiles = new ArrayList<>();
        ProductFile productFile1 = mock(ProductFile.class);
        ProductFile productFile2 = mock(ProductFile.class);
        when(productFile1.getId()).thenReturn(UUID.fromString("ec65c371-35ed-4d0e-8f2b-d90678db4c4d"));
        when(productFile2.getId()).thenReturn(UUID.fromString("5320dfb9-6ed8-4da3-b85f-0a3c58fb6f19"));
        productFiles.add(productFile1);
        productFiles.add(productFile2);
        when(productImageBlobService.retrieveProductFilesFromBlobService(UUID.fromString(id)))
                .thenReturn(productFiles);

        String logoURIImage = "https://example.com/logo.png";
        when(personalizationStub.obtainPersonalizationSettings(Mockito.any(), Mockito.anyLong())).thenReturn(
                new ObtainPersonalizationSettingsOutput(logoURIImage, null, null, null));

        List<ParameterValue> params = component.getParams(id);

        assertEquals(3, params.size());
        assertEquals("pedido_id", params.get(0).getName());
        assertEquals(id, params.get(0).getValue());
        assertEquals("productFiles", params.get(1).getName());
        assertEquals(productFiles, params.get(1).getValue());
        assertEquals("logo-image", params.get(2).getName());
        assertEquals(logoURIImage, params.get(2).getValue());
    }

    @Test
    public void testGetParamsWithEmptyProductFiles() {
        String id = "d1b18c7f-6c46-4f24-9c35-9d9bf849b8fa";

        when(productImageBlobService.retrieveProductFilesFromBlobService(UUID.fromString(id)))
                .thenReturn(new ArrayList<>());

        String logoURIImage = "https://example.com/logo.png";
        when(personalizationStub.obtainPersonalizationSettings(Mockito.any(), Mockito.anyLong())).thenReturn(
                new ObtainPersonalizationSettingsOutput(logoURIImage, null, null, null));

        List<ParameterValue> params = component.getParams(id);

        assertEquals(1, params.size());
        assertEquals("pedido_id", params.get(0).getName());
        assertEquals(id, params.get(0).getValue());
    }