public class

Strict

extends Object
implements Answer<T>
java.lang.Object
   ↳ com.atlassian.jira.mock.Strict<T>

Class Overview

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!

Summary

Public Constructors
Strict()
Public Methods
T answer(InvocationOnMock invocationOnMock)
Throws an exception that reports the unexpected method invocation.
static <T> Strict<T> strict(Class<T> tClass)
Factory method that will infer the correct type from the supplied class
static <T> Strict<T> strict()
Factory method that will infer the correct type from the context
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.mockito.stubbing.Answer

Public Constructors

public Strict ()

Public Methods

public T answer (InvocationOnMock invocationOnMock)

Throws an exception that reports the unexpected method invocation.

Parameters
invocationOnMock the invocation that reached us
Returns
  • never returns normally
Throws
AssertionFailedError reporting the invocation
Throwable

public static Strict<T> strict (Class<T> tClass)

Factory method that will infer the correct type from the supplied class

public static Strict<T> strict ()

Factory method that will infer the correct type from the context