public interface DeprecatedOngoingStubbing<T> extends IOngoingStubbing
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)| Modifier and Type | Method and Description |
|---|---|
DeprecatedOngoingStubbing<T> |
toAnswer(Answer<?> answer)
Set a generic Answer for the stubbed method.
|
DeprecatedOngoingStubbing<T> |
toReturn(T value)
Set a return value for the stubbed method.
|
DeprecatedOngoingStubbing<T> |
toThrow(Throwable throwable)
Set a Throwable to be thrown when the stubbed method is called.
|
DeprecatedOngoingStubbing<T> toReturn(T value)
stub(mock.someMethod()).toReturn(10);See examples in javadoc for
Mockito.stub(T)value - return valueDeprecatedOngoingStubbing<T> toThrow(Throwable throwable)
stub(mock.someMethod()).toThrow(new RuntimeException());If throwable is a checked exception then it has to match one of the checked exceptions of method signature. See examples in javadoc for
Mockito.stub(T)throwable - to be thrown on method invocationDeprecatedOngoingStubbing<T> toAnswer(Answer<?> answer)
stub(mock.someMethod(10)).toAnswer(new Answer<Integer>() {
public Integer answer(InvocationOnMock invocation) throws Throwable {
return (Integer) invocation.getArguments()[0];
}
}
answer - the custom answer to execute.Copyright © 2018. All rights reserved.