• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockito.invocation;
6 
7 import java.io.Serializable;
8 import java.lang.reflect.Method;
9 
10 import org.mockito.MockitoFramework;
11 import org.mockito.mock.MockCreationSettings;
12 
13 /**
14  * Available via {@link MockitoFramework#getInvocationFactory()}.
15  * Provides means to create instances of {@link Invocation} objects.
16  * Useful for framework integrations that need to programmatically simulate method calls on mock objects.
17  * To simulate a method call on mock, one needs an instance of {@link Invocation}.
18  * <p>
19  * Please don't provide your own implementation of {@link Invocation} type.
20  * Mockito team needs flexibility to add new methods to this interface if we need to.
21  * If you integrate Mockito framework and you need an instance of {@link Invocation}, use {@link #createInvocation(Object, MockCreationSettings, Method, RealMethodBehavior, Object...)}.
22  *
23  * @since 2.10.0
24  */
25 public interface InvocationFactory {
26 
27     /**
28      * Behavior of the real method.
29      *
30      * @since 2.14.0
31      */
32     interface RealMethodBehavior<R> extends Serializable {
call()33         R call() throws Throwable;
34     }
35 
36     /**
37      * Creates instance of an {@link Invocation} object.
38      * This method is useful for framework integrators to programmatically simulate method calls on mocks using {@link MockHandler}.
39      * It enables advanced framework integrations.
40      *
41      * @param target the mock object the method is invoked on.
42      * @param settings creation settings of the mock object.
43      * @param method java method invoked on mock.
44      * @param realMethod real method behavior. Needed for spying / invoking real behavior on mock objects.
45      * @param args the java method arguments
46      *
47      * @return invocation instance
48      * @since 2.14.0
49      */
createInvocation( Object target, MockCreationSettings settings, Method method, RealMethodBehavior realMethod, Object... args)50     Invocation createInvocation(
51             Object target,
52             MockCreationSettings settings,
53             Method method,
54             RealMethodBehavior realMethod,
55             Object... args);
56 }
57