Package org.mockito.stubbing
Interface Stubber
- All Superinterfaces:
BaseStubber
Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() style
Example:
doThrow(new RuntimeException()).when(mockedList).clear();
//following throws RuntimeException:
mockedList.clear();
Also useful when stubbing consecutive calls:
doThrow(new RuntimeException("one")).
doThrow(new RuntimeException("two"))
.when(mock).someVoidMethod();
Read more about those methods:
See examples in javadoc for Mockito
-
Method Summary
Modifier and TypeMethodDescription<T> T
when
(T mock) Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() styleMethods inherited from interface org.mockito.stubbing.BaseStubber
doAnswer, doCallRealMethod, doNothing, doReturn, doReturn, doThrow, doThrow, doThrow
-
Method Details
-
when
<T> T when(T mock) Allows to choose a method when stubbing in doThrow()|doAnswer()|doNothing()|doReturn() styleExample:
Read more about those methods:doThrow(new RuntimeException()) .when(mockedList).clear(); //following throws RuntimeException: mockedList.clear();
See examples in javadoc for
Mockito
- Parameters:
mock
- The mock- Returns:
- select method for stubbing
-