简体   繁体   中英

How to throw exception using PowerMock/PowerMockito/Mockito when a call to void method is made?

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 :

  1. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM