Package org.mockito.stubbing
Interface DeprecatedOngoingStubbing<T>
- All Superinterfaces:
IOngoingStubbing
- All Known Implementing Classes:
BaseStubbing
,ConsecutiveStubbing
,OngoingStubbingImpl
Stubs a method call with return value or an exception. E.g:
stub(mock.someMethod()).toReturn(10);
//you can use flexible argument matchers, e.g:
stub(mock.someMethod(anyString())).toReturn(10);
//setting exception to be thrown:
stub(mock.someMethod("some arg")).toThrow(new RuntimeException());
//you can stub with different behavior for consecutive method calls.
//Last stubbing (e.g: toReturn("foo")) determines the behavior for further consecutive calls.
stub(mock.someMethod("some arg"))
.toThrow(new RuntimeException())
.toReturn("foo");
See examples in javadoc for Mockito.stub(T)
-
Method Summary
Modifier and TypeMethodDescriptionSet a generic Answer for the stubbed method.Set a return value for the stubbed method.Set a Throwable to be thrown when the stubbed method is called.
-
Method Details
-
toReturn
Set a return value for the stubbed method. E.g:
See examples in javadoc forstub(mock.someMethod()).toReturn(10);
Mockito.stub(T)
- Parameters:
value
- return value- Returns:
- iOngoingStubbing object that allows stubbing consecutive calls
-
toThrow
Set a Throwable to be thrown when the stubbed method is called. E.g:
If throwable is a checked exception then it has to match one of the checked exceptions of method signature. See examples in javadoc forstub(mock.someMethod()).toThrow(new RuntimeException());
Mockito.stub(T)
- Parameters:
throwable
- to be thrown on method invocation- Returns:
- iOngoingStubbing object that allows stubbing consecutive calls
-
toAnswer
Set a generic Answer for the stubbed method. E.g:stub(mock.someMethod(10)).toAnswer(new Answer<Integer>() { public Integer answer(InvocationOnMock invocation) throws Throwable { return (Integer) invocation.getArguments()[0]; } }
- Parameters:
answer
- the custom answer to execute.- Returns:
- iOngoingStubbing object that allows stubbing consecutive calls
-