Package com.atlassian.jira.mock
Class Strict<T>
java.lang.Object
com.atlassian.jira.mock.Strict<T>
- All Implemented Interfaces:
org.mockito.stubbing.Answer<T>
Mockito mocks are lenient by default, and this makes them throw an exception for
anything that was not expressly stubbed. 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.
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!
- Since:
- v6.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionanswer(org.mockito.invocation.InvocationOnMock invocationOnMock) Throws an exception that reports the unexpected method invocation.static <T> Treject(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 contextstatic <T> Strict<T> Factory method that will infer the correct type from the supplied class
-
Constructor Details
-
Strict
public Strict()
-
-
Method Details
-
strict
Factory method that will infer the correct type from the context -
strict
Factory method that will infer the correct type from the supplied class -
reject
public static <T> T reject(T mockOrSpy) Factory method for stubbing an individual method as rejected.Example:
>Strict.reject(mock).methodThatShouldNotGetCalled(); -
answer
Throws an exception that reports the unexpected method invocation.- Specified by:
answerin interfaceorg.mockito.stubbing.Answer<T>- Parameters:
invocationOnMock- the invocation that reached us- Returns:
- never returns normally
- Throws:
AssertionError- reporting the invocationThrowable
-