testing powermock simulate http server time out for client call

前端 未结 2 954
暖寄归人
暖寄归人 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:01

    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

提交回复
热议问题