Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.6 kB
2
Indexable
Never
package br.com.senior.erpxcomven.pedido.converter.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;

import java.util.Objects;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import br.com.senior.erpxcomven.foundation.E001endEntity;
import br.com.senior.erpxcomven.foundation.E001pesEntity;
import br.com.senior.erpxcomven.pedido.ShippingAddress;

public class ShippingAddressConverterTest {
    
    @Mock
    private E001endEntity e001endEntity;
    
    @Mock
    private E001pesEntity e001pesEntity;
    
    @InjectMocks
    private ShippingAddressConverter shippingAddressConverter;
    
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testConvertNullShippingAddress() {
        assertNull(shippingAddressConverter.convert(null));
    }
    
    @Test
    public void testConvertValidShippingAddress() {
        when(e001endEntity.getE001pes()).thenReturn(e001pesEntity);
        when(e001endEntity.getEndPes()).thenReturn("Rua Teste");
        when(e001endEntity.getNenEnd()).thenReturn("123");
        when(e001endEntity.getCplEnd()).thenReturn("Apto 123");
        when(e001endEntity.getBaiEnd()).thenReturn("Bairro Teste");
        when(e001endEntity.getPostalCode()).thenReturn("12345678");
        when(e001pesEntity.getCnpCpf()).thenReturn("12345678900");
        when(e001pesEntity.getNomPes()).thenReturn("Fulano de Tal");
        
        ShippingAddress expected = new ShippingAddress();
        expected.address = "Rua Teste";
        expected.addressNumber = "123";
        expected.addressComplement = "Apto 123";
        expected.neighborhood = "Bairro Teste";
        expected.postCode = "12345678";
        expected.document = "12345678900";
        expected.name = "Fulano de Tal";
        
        ShippingAddress actual = shippingAddressConverter.convert(e001endEntity);
        
        assertEquals(expected.address, actual.address);
        assertEquals(expected.addressNumber, actual.addressNumber);
        assertEquals(expected.addressComplement, actual.addressComplement);
        assertEquals(expected.neighborhood, actual.neighborhood);
        assertEquals(expected.postCode, actual.postCode);
        assertEquals(expected.document, actual.document);
        assertEquals(expected.name, actual.name);
    }
}