jeudi 27 juin 2019

Test a method using the org.springframework.test.util.ReflectionTestUtils

I have a class method that I would like test

public class EllaDtoConverter {


    private static void convertToIp( final IrisBo irisBo, EllaRequestDto request ) {

        if( nonNull( irisBo.getDevice() ) ) {
            request.setIp( irisBo.getDevice().getIpAddress() );
        }
    }
}

My test is provided

@Test
public void testConvertToIp() {

    assertNotNull( validIrisBo.getDevice() );
    assertNotNull( validIrisBo.getDevice().getIpAddress() );

    EllaRequestDto ellaRequestDto = new EllaRequestDto();

    ReflectionTestUtils.invokeMethod( ellaRequestDto, "setIp", validIrisBo.getDevice().getIpAddress() );
}

Does it okay to leave it like this or I have a better option to test?





Aucun commentaire:

Enregistrer un commentaire