Test a private static method with the PowerMock

Keywords: java mockito powermock


I have a POJO class provided below,

@JsonInclude( JsonInclude.Include.NON_NULL )
public class EllaRequestDto extends BaseDto {

    private String trackingId;

    private String email;

    private String ip;

    private String firstName;

    private String lastName;

    private AddressDto billingAddress;

    private AddressDto shippingAddress;

    private TransactionDto transaction;

    private ServiceDto service;

I also write a converter provided below,

public final class EllaDtoConverter {

    private EllaDtoConverter() {
        throw new PrivateConstructorException();

     * Map IrisBo attributes to Ella-RequestDTO.
     * @param irisBo irisEo object
     * @return RequestDto ella requestDTO
    public static EllaRequestDto convertToRequest( final IrisBo irisBo ) throws IllegalArgumentException {

        notNull( irisBo, "Bad argument: IrisBo resolved to null" );
        notNull( irisBo.getBuyer().getEmail(), "Bad argument: Email Address resolved to null" );

        final AddressDto shipAddressDto = convertToShipAddressDto( irisBo );
        final AddressDto billAddressDto = convertToBillAddressDto( irisBo );
        final ServiceDto serviceDto = convertToServiceDto( irisBo );
        final TransactionDto transactionDto = convertToTransactionDto( irisBo );

        final EllaRequestDto request = new EllaRequestDto();

        request.setTrackingId( irisBo.getRequestInfo().getTransactionId() );
        request.setEmail( irisBo.getBuyer().getEmail() );

        convertToIp( irisBo, request );
        convertToNames( irisBo, request );

        request.setBillingAddress( shipAddressDto );
        request.setShippingAddress( billAddressDto );
        request.setTransaction( transactionDto );
        request.setService( serviceDto );

        return request;

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

        if( !isNull( irisBo.getBuyer() ) ) {
            request.setLastName( irisBo.getBuyer().getLastName() );
            request.setFirstName( irisBo.getBuyer().getFirstName() );

    // ....... some code 

My test class is here,

@RunWith( MockitoJUnitRunner.class )
public class EllaDtoConverterTest {

    private EllaRequestDto ellaRequestDto;

    private IrisBo validIrisBo;

    private static final double DELTA = 1e-15;

    private String validTrackingId;
    private String validEmailAddress;
    private String validIpAddress;
    private String validFirstName;
    private String validLastName;

    public ExpectedException expectedException = ExpectedException.none();

    public void setup() {

        validIrisBo = EllaTestDataProvider.createValidIrisBoWithoutRequest();

        validTrackingId = "valid-trx-id";
        validEmailAddress = "test@test.com";
        validIpAddress = "";
        validFirstName = "Max";
        validLastName = "Musterman";

     // .. some code 


I am able to do the null check for the irisBo.getBuyer() inside the EllaDtoConverter::convertToNames method. How do I test the request.setFirstName and request.setLastName calls inside?