Java – how to use jmockit to pass an empty string to a private method during unit testing?

The following is the private method in my datatap class. I tried to JUnit test this private method with jmockit –

private void parseResponse(String response) throws Exception {
    if (response != null) {
        // some code
    }
}

So here is the JUnit test I wrote, but in the case of null, it will throw NPE in some way on the JUnit test itself

DataTap tap = new DataTap();
Deencapsulation.invoke(tap,"parseResponse","hello");

// this line throws NPE
Deencapsulation.invoke(tap,null);

So my question is – is there any way to pass an empty string to the parseresponse method using jmockit as part of the JUnit test?

That's what I see on this line –

Solution

A quick browse at the documentation indicates that you cannot use this signature for operations:

If this is the case, the class object and the instance are passed in

Deencapsulation.invoke(tap,String.class);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>