testing powermock simulate http server time out for client call

前端 未结 2 988
暖寄归人
暖寄归人 2021-01-28 07:41

i need to write testcase for connectTimeout and SocketTimeout exception. Am using powerMock to create mock objects. Below is my code. But am getting null pointer exception for m

2条回答
  •  青春惊慌失措
    2021-01-28 08:07

    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)

提交回复
热议问题