-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
DefaultInvocationFactory.java
89 lines (80 loc) · 2.96 KB
/
DefaultInvocationFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright (c) 2017 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.invocation;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;
import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.internal.creation.DelegatingMethod;
import org.mockito.internal.invocation.mockref.MockWeakReference;
import org.mockito.internal.progress.SequenceNumber;
import org.mockito.invocation.Invocation;
import org.mockito.invocation.InvocationFactory;
import org.mockito.invocation.Location;
import org.mockito.mock.MockCreationSettings;
public class DefaultInvocationFactory implements InvocationFactory {
public Invocation createInvocation(
Object target,
MockCreationSettings settings,
Method method,
final Callable realMethod,
Object... args) {
RealMethod superMethod = new RealMethod.FromCallable(realMethod);
return createInvocation(target, settings, method, superMethod, args);
}
@Override
public Invocation createInvocation(
Object target,
MockCreationSettings settings,
Method method,
RealMethodBehavior realMethod,
Object... args) {
RealMethod superMethod = new RealMethod.FromBehavior(realMethod);
return createInvocation(target, settings, method, superMethod, args);
}
private Invocation createInvocation(
Object target,
MockCreationSettings settings,
Method method,
RealMethod superMethod,
Object[] args) {
return createInvocation(target, method, args, superMethod, settings);
}
public static InterceptedInvocation createInvocation(
Object mock,
Method invokedMethod,
Object[] arguments,
RealMethod realMethod,
MockCreationSettings settings,
Location location) {
return new InterceptedInvocation(
new MockWeakReference<Object>(mock),
createMockitoMethod(invokedMethod, settings),
arguments,
realMethod,
location,
SequenceNumber.next());
}
private static InterceptedInvocation createInvocation(
Object mock,
Method invokedMethod,
Object[] arguments,
RealMethod realMethod,
MockCreationSettings settings) {
return createInvocation(
mock,
invokedMethod,
arguments,
realMethod,
settings,
Plugins.getLocationFactory().create());
}
private static MockitoMethod createMockitoMethod(Method method, MockCreationSettings settings) {
if (settings.isSerializable()) {
return new SerializableMethod(method);
} else {
return new DelegatingMethod(method);
}
}
}