/* * Copyright (c) 2007 Mockito contributors * This program is made available under the terms of the MIT License. */ package org.mockito.plugins; import org.mockito.Incubating; import org.mockito.invocation.MockHandler; import org.mockito.mock.MockCreationSettings; /** * The facility to create mocks. * *
By default, an internal cglib/asm/objenesis based implementation is used.
* *{@code MockMaker} is an extension point that makes it possible to use custom dynamic proxies * and avoid using the default cglib/asm/objenesis implementation. * For example, the android users can use a MockMaker that can work with Dalvik virtual machine * and hence bring Mockito to android apps developers.
* *Suppose you wrote an extension to create mocks with some Awesome library, in order to tell * Mockito to use it you need to put in your classpath: *
org.awesome.mockito.AwesomeMockMaker
that extends the MockMaker
.mockito-extensions/org.mockito.plugins.MockMaker
". The content of this file is
* exactly a one line with the qualified name: org.awesome.mockito.AwesomeMockMaker
.Note that if several mockito-extensions/org.mockito.plugins.MockMaker
files exists in the classpath
* Mockito will only use the first returned by the standard {@link ClassLoader#getResource} mechanism.
*
* @see org.mockito.mock.MockCreationSettings
* @see org.mockito.invocation.MockHandler
* @since 1.9.5
*/
@Incubating
public interface MockMaker {
/**
* If you want to provide your own implementation of {@code MockMaker} this method should:
*
settings.getTypeToMock
.
* @return The mock instance.
* @since 1.9.5
*/
The invocation handler actually store invocations to achieve * stubbing and verification. In order to reset the mock, we pass * a new instance of the invocation handler.
* *Your implementation should make sure the {@code newHandler} is correctly associated to passed {@code mock}
* * @param mock The mock instance whose invocation handler is to be replaced. * @param newHandler The new invocation handler instance. * @param settings The mock settings - should you need to access some of the mock creation details. * @since 1.9.5 */ void resetMock( Object mock, MockHandler newHandler, MockCreationSettings settings ); }