-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
PluginRegistry.java
103 lines (87 loc) · 3.79 KB
/
PluginRegistry.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright (c) 2016 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.configuration.plugins;
import org.mockito.internal.creation.instance.InstantiatorProviderAdapter;
import org.mockito.plugins.*;
class PluginRegistry {
private final PluginSwitch pluginSwitch =
new PluginLoader(new DefaultPluginSwitch()).loadPlugin(PluginSwitch.class);
private final MockMaker mockMaker =
new PluginLoader(pluginSwitch, DefaultMockitoPlugins.INLINE_ALIAS)
.loadPlugin(MockMaker.class);
private final MemberAccessor memberAccessor =
new PluginLoader(pluginSwitch, DefaultMockitoPlugins.MODULE_ALIAS)
.loadPlugin(MemberAccessor.class);
private final StackTraceCleanerProvider stackTraceCleanerProvider =
new PluginLoader(pluginSwitch).loadPlugin(StackTraceCleanerProvider.class);
private final InstantiatorProvider2 instantiatorProvider;
private final AnnotationEngine annotationEngine =
new PluginLoader(pluginSwitch).loadPlugin(AnnotationEngine.class);
private final MockitoLogger mockitoLogger =
new PluginLoader(pluginSwitch).loadPlugin(MockitoLogger.class);
PluginRegistry() {
Object impl =
new PluginLoader(pluginSwitch)
.loadPlugin(InstantiatorProvider2.class, InstantiatorProvider.class);
if (impl instanceof InstantiatorProvider) {
instantiatorProvider = new InstantiatorProviderAdapter((InstantiatorProvider) impl);
} else {
instantiatorProvider = (InstantiatorProvider2) impl;
}
}
/**
* The implementation of the stack trace cleaner
*/
StackTraceCleanerProvider getStackTraceCleanerProvider() {
// TODO we should throw some sensible exception if this is null.
return stackTraceCleanerProvider;
}
/**
* Returns the implementation of the mock maker available for the current runtime.
*
* <p>Returns {@link org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker} if no
* {@link org.mockito.plugins.MockMaker} extension exists or is visible in the current classpath.</p>
*/
MockMaker getMockMaker() {
return mockMaker;
}
/**
* Returns the implementation of the member accessor available for the current runtime.
*
* <p>Returns {@link org.mockito.internal.util.reflection.ReflectionMemberAccessor} if no
* {@link org.mockito.plugins.MockMaker} extension exists or is visible in the current classpath.</p>
*/
MemberAccessor getMemberAccessor() {
return memberAccessor;
}
/**
* Returns the instantiator provider available for the current runtime.
*
* <p>Returns {@link org.mockito.internal.creation.instance.DefaultInstantiatorProvider} if no
* {@link org.mockito.plugins.InstantiatorProvider2} extension exists or is visible in the
* current classpath.</p>
*/
InstantiatorProvider2 getInstantiatorProvider() {
return instantiatorProvider;
}
/**
* Returns the annotation engine available for the current runtime.
*
* <p>Returns {@link org.mockito.internal.configuration.InjectingAnnotationEngine} if no
* {@link org.mockito.plugins.AnnotationEngine} extension exists or is visible in the current classpath.</p>
*/
AnnotationEngine getAnnotationEngine() {
return annotationEngine;
}
/**
* Returns the logger available for the current runtime.
*
* <p>Returns {@link org.mockito.internal.util.ConsoleMockitoLogger} if no
* {@link org.mockito.plugins.MockitoLogger} extension exists or is visible in the current classpath.</p>
*/
MockitoLogger getMockitoLogger() {
return mockitoLogger;
}
}