public class Strict<T> extends Object implements org.mockito.stubbing.Answer<T>
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.
Why would you do 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. 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.
|
static <T> T |
reject(T mockOrSpy)
Factory method for stubbing an individual method as rejected.
|
static <T> Strict<T> |
strict()
Factory method that will infer the correct type from the context
|
static <T> Strict<T> |
strict(Class<T> tClass)
Factory method that will infer the correct type from the supplied class
|
public static <T> Strict<T> strict()
public static <T> Strict<T> strict(Class<T> tClass)
public static <T> T reject(T mockOrSpy)
Example:
Strict.reject(mock).methodThatShouldNotGetCalled();
>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 © 2002-2022 Atlassian. All Rights Reserved.