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?
As explained in the documentation :
- Stubbing void methods with exceptions
doThrow(new RuntimeException()).when(mockedList).clear();
//following throws RuntimeException:
mockedList.clear();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.