testing powermock simulate http server time out for client call

对着背影说爱祢 提交于 2019-12-02 10:05:10

Acording to powermock documentation, in the section mock constructor, you should be doing something like that:

URL mockURL = PowerMockito.mock(URL.class);
expectNew(File.class, url).andReturn(mockURL);
replay(mockURL, File.class);

Also, be sure to use annotations @PrepareForTest(Sender.class) and @RunWith(PowerMockRunner.class)

Finally i was able to solve it. Incase some gets the same issue again. In my code issue was withArguments line. I was trying to pass

String url="https://www.google.co.in/";

as the Url parameter. But in the actual it was null.

URL mockURL = PowerMockito.mock(URL.class); PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(mockURL);

withArguments try to match if the parameters are same. On having same url paramter on my mock and actual object in code i was able to proceed with out null pointer exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!