public class Strict<T> extends Object implements org.mockito.stubbing.Answer<T>
Note that this means the when(mock.method()) style of stubbing will not work because the
mock.method() call will throw an exception instead of returning null. You will
need to use the doReturn(null).when(mock).method() style of stubbing, instead. Alternatively,
you could wrap this in a flip-flop and flip
it only once you are done stubbing your mocks.
Why would you do any of this instead of just letting it throw a NullPointerException when the
unstubbed method is invoked? Because this will actually tell you what the unexpected invocation was,
which is much more helpful!
| Constructor and Description |
|---|
Strict() |
| Modifier and Type | Method and Description |
|---|---|
T |
answer(org.mockito.invocation.InvocationOnMock invocationOnMock)
Throws an exception that reports the unexpected method invocation.
|
public T answer(org.mockito.invocation.InvocationOnMock invocationOnMock) throws Throwable
answer in interface org.mockito.stubbing.Answer<T>invocationOnMock - the invocation that reached usAssertionError - reporting the invocationThrowableCopyright © 2017 Atlassian. All rights reserved.