How to throw exception using PowerMock/PowerMockito/Mockito when a call to void method is made? Since the method is a void method so Mockito is not showing the option to throw exception. How can I go about it?
Asked
Active
Viewed 1.2k times
2
-
Possible duplicate of [How to mock a void static method to throw exception with Powermock?](http://stackoverflow.com/questions/7483628/how-to-mock-a-void-static-method-to-throw-exception-with-powermock) – Eric Apr 03 '17 at 18:29
1 Answers
3
As explained in the documentation:
- Stubbing void methods with exceptions
doThrow(new RuntimeException()).when(mockedList).clear();
//following throws RuntimeException:
mockedList.clear();

JB Nizet
- 678,734
- 91
- 1,224
- 1,255