/* * Copyright (c) 2007 Mockito contributors * This program is made available under the terms of the MIT License. */ package org.mockito; import org.mockito.ArgumentMatchers; import org.mockito.MockSettings; import org.mockito.internal.creation.MockSettingsImpl; import org.mockito.stubbing.Answer; import org.mockito.stubbing.OngoingStubbing; import org.mockito.internal.MockitoCore; import org.mockito.MockSettings; import org.mockito.stubbing.Stubber; public class Mockito extends ArgumentMatchers { static final MockitoCore MOCKITO_CORE = new MockitoCore(); public static MockSettings withSettings() { return new MockSettings() { }; } /** * Creates a mock object of the requested class or interface. *
* See examples in javadoc for the {@link Mockito} class.
*
* @param reified don't pass any values to it. It's a trick to detect the
* class/interface you
* want to mock.
* @return the mock object.
* @since 4.10.0
*/
@SafeVarargs
public static
* See examples in javadoc for the {@link Mockito} class.
*
* @param defaultAnswer the default answer to use.
* @param reified don't pass any values to it. It's a trick to detect the
* class/interface you
* want to mock.
* @return the mock object.
* @since 5.1.0
*/
@SafeVarargs
public static
* See examples in javadoc for the {@link Mockito} class.
*
* @param name the mock name to use.
* @param reified don't pass any values to it. It's a trick to detect the
* class/interface you
* want to mock.
* @return the mock object.
* @since 5.1.0
*/
@SafeVarargs
public static
* See examples in javadoc for the {@link Mockito} class.
*
* @param settings the mock settings to use.
* @param reified don't pass any values to it. It's a trick to detect the
* class/interface you
* want to mock.
* @return the mock object.
* @since 5.1.0
*/
@SafeVarargs
public static
* See examples in javadoc for {@link Mockito} class
*
* @param classToMock class or interface to mock
* @return mock object
*/
public static
* Beware that naming mocks is not a solution for complex code which uses too
* many mocks or collaborators.
* If you have too many mocks then refactor the code so that it's easy to
* test/debug without necessity of naming mocks.
*
* If you use
*
* See examples in javadoc for {@link Mockito} class
*
* @param classToMock class or interface to mock
* @param name of the mock
* @return mock object
*/
public static
* It is the default answer so it will be used only when you don't stub
* the method call.
*
*
* See examples in javadoc for {@link Mockito} class
*
* The number of configuration points for a mock will grow,
* so we need a fluent way to introduce new configuration without adding more
* and more overloaded Mockito.mock() methods.
* Hence {@link MockSettings}.
*
*
* See also {@link Mockito#withSettings()}
*
* See examples in javadoc for {@link Mockito} class
*
* @param classToMock class or interface to mock
* @param mockSettings additional mock settings
* @return mock object
*/
public static @Mock annotation then you've got naming mocks
* for free! @Mock uses field name as mock name.
* {@link Mock Read more.}
*
*
*
*
* Foo mock = mock(Foo.class, RETURNS_SMART_NULLS);
* Foo mockTwo = mock(Foo.class, new YourOwnAnswer());
*
*
*
*
* Use it carefully and occasionally. What might be reason your test
* needs non-standard mocks?
* Is the code under test so complicated that it requires non-standard mocks?
* Wouldn't you prefer to refactor the code under test, so that it is testable
* in a simple way?
*
* Listener mock = mock(Listener.class, withSettings()
* .name("firstListner").defaultBehavior(RETURNS_SMART_NULLS));
* );
*
*