Class FluentAnswer<T extends org.camunda.bpm.engine.query.Query<?,R>,R>
- java.lang.Object
-
- org.camunda.community.mockito.answer.FluentAnswer<T,R>
-
- Type Parameters:
T- the return type of the answer
- All Implemented Interfaces:
org.mockito.stubbing.Answer<T>
public final class FluentAnswer<T extends org.camunda.bpm.engine.query.Query<?,R>,R> extends Object implements org.mockito.stubbing.Answer<T>
A fluent answer always returns the mock instance itself for all methods that have the same return type as the mock instance. This makes it possible to easily mock fluent-api behaviour without chaining the when/then stubbings or relying on deep stubs.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tanswer(org.mockito.invocation.InvocationOnMock invocation)Returns the mock itself if return type and mock type match (assume fluent api).static <T extends org.camunda.bpm.engine.query.Query<?,R>,R>
FluentAnswer<T,R>createAnswer(Class<T> type)Creates a new instance for the given type.static <T extends org.camunda.bpm.engine.query.Query<?,R>,R>
TcreateMock(Class<T> type)Creates a new mock of given type with a fluent default answer already set up.
-
-
-
Method Detail
-
createMock
public static <T extends org.camunda.bpm.engine.query.Query<?,R>,R> T createMock(Class<T> type)
Creates a new mock of given type with a fluent default answer already set up.- Type Parameters:
T- generic parameter for type of mock- Parameters:
type- type of mock- Returns:
- new mock instance of type T with default fluent answer.
-
createAnswer
public static <T extends org.camunda.bpm.engine.query.Query<?,R>,R> FluentAnswer<T,R> createAnswer(Class<T> type)
Creates a new instance for the given type.- Type Parameters:
T- generic parameter of the return type- Parameters:
type- the return type of the answer- Returns:
- new Answer that returns the mock itself
-
answer
public T answer(@Nonnull org.mockito.invocation.InvocationOnMock invocation) throws Throwable
Returns the mock itself if return type and mock type match (assume fluent api).- Specified by:
answerin interfaceorg.mockito.stubbing.Answer<T extends org.camunda.bpm.engine.query.Query<?,R>>- Parameters:
invocation- the method invocation. If its return type equals the mock type, just return the mock.- Returns:
- the mock itself or null (meaning further stubbing is required).
- Throws:
Throwable- when anything fails
-
-