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
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
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)