All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.mockito.Answers Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package com.fitbur.mockito;

import com.fitbur.mockito.internal.stubbing.answers.CallsRealMethods;
import com.fitbur.mockito.internal.stubbing.defaultanswers.TriesToReturnSelf;
import com.fitbur.mockito.internal.stubbing.defaultanswers.GloballyConfiguredAnswer;
import com.fitbur.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
import com.fitbur.mockito.internal.stubbing.defaultanswers.ReturnsMocks;
import com.fitbur.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls;
import com.fitbur.mockito.invocation.InvocationOnMock;
import com.fitbur.mockito.stubbing.Answer;

/**
 * Enumeration of pre-configured mock answers
 * 

* You can use it to pass extra parameters to @Mock annotation, see more info here: {@link Mock} *

* Example: *


 *   @Mock(answer = RETURNS_DEEP_STUBS) UserProvider userProvider;
 * 
* This is not the full list of Answers available in Mockito. Some interesting answers can be found in com.fitbur.mockito.stubbing.answers package. */ public enum Answers implements Answer{ /** * The default configured answer of every mock. * *

Please see the {@link com.fitbur.mockito.Mockito#RETURNS_DEFAULTS} documentation for more details.

* * @see com.fitbur.mockito.Mockito#RETURNS_DEFAULTS */ RETURNS_DEFAULTS(new GloballyConfiguredAnswer()), /** * An answer that returns smart-nulls. * *

Please see the {@link com.fitbur.mockito.Mockito#RETURNS_SMART_NULLS} documentation for more details.

* * @see com.fitbur.mockito.Mockito#RETURNS_SMART_NULLS */ RETURNS_SMART_NULLS(new ReturnsSmartNulls()), /** * An answer that returns mocks (not stubs). * *

Please see the {@link com.fitbur.mockito.Mockito#RETURNS_MOCKS} documentation for more details.

* * @see com.fitbur.mockito.Mockito#RETURNS_MOCKS */ RETURNS_MOCKS(new ReturnsMocks()), /** * An answer that returns deep stubs (not mocks). * *

Please see the {@link com.fitbur.mockito.Mockito#RETURNS_DEEP_STUBS} documentation for more details.

* * @see com.fitbur.mockito.Mockito#RETURNS_DEEP_STUBS */ RETURNS_DEEP_STUBS(new ReturnsDeepStubs()), /** * An answer that calls the real methods (used for partial mocks). * *

Please see the {@link com.fitbur.mockito.Mockito#CALLS_REAL_METHODS} documentation for more details.

* * @see com.fitbur.mockito.Mockito#CALLS_REAL_METHODS */ CALLS_REAL_METHODS(new CallsRealMethods()), /** * An answer that tries to return itself. This is useful for mocking {@code Builders}. * *

Please see the {@link com.fitbur.mockito.Mockito#RETURNS_SELF} documentation for more details.

* * @see com.fitbur.mockito.Mockito#RETURNS_SELF */ RETURNS_SELF(new TriesToReturnSelf()) ; private final Answer implementation; Answers(Answer implementation) { this.implementation = implementation; } public Object answer(InvocationOnMock invocation) throws Throwable { return implementation.answer(invocation); } }