Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.9 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 org.junit.Before;
import org.junit.Test;

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

public class ShippingAddressConverterTest {

    private ShippingAddressConverter shippingAddressConverter;

    @Before
    public void setUp() {
        shippingAddressConverter = new ShippingAddressConverter();
    }

    @Test
    public void testConvertShouldReturnNullWhenShippingAddressIsNull() {
        ShippingAddress dto = shippingAddressConverter.convert(null);
        assertNull(dto);
    }

    @Test
    public void testConvertShouldReturnCorrectShippingAddressDto() {
        E001pesEntity e001pes = new E001pesEntity();
        e001pes.setCnpCpf("12345678900");
        e001pes.setNomPes("John Doe");

        E001endEntity shippingAddress = new E001endEntity();
        shippingAddress.setEndPes("Main Street");
        shippingAddress.setNenEnd("123");
        shippingAddress.setCplEnd("Apt 456");
        shippingAddress.setBaiEnd("Downtown");
        shippingAddress.setPostalCode("12345-678");
        shippingAddress.setE001pes(e001pes);

        ShippingAddress dto = shippingAddressConverter.convert(shippingAddress);

        assertEquals(shippingAddress.getEndPes(), dto.address);
        assertEquals(shippingAddress.getNenEnd(), dto.addressNumber);
        assertEquals(shippingAddress.getCplEnd(), dto.addressComplement);
        assertEquals(shippingAddress.getBaiEnd(), dto.neighborhood);
        assertEquals(shippingAddress.getPostalCode(), dto.postCode);
        assertEquals(e001pes.getCnpCpf(), dto.document);
        assertEquals(e001pes.getNomPes(), dto.name);
    }

}