6
6
import org .slf4j .LoggerFactory ;
7
7
8
8
import java .util .ArrayList ;
9
- import java .util .HashMap ;
10
9
import java .util .LinkedHashMap ;
11
10
import java .util .List ;
12
11
import java .util .Map ;
@@ -30,12 +29,7 @@ class DBuilder implements Builder {
30
29
/**
31
30
* The beans created and added to the context during building.
32
31
*/
33
- private final DBeanMap beanMap = new DBeanMap ();
34
-
35
- /**
36
- * Supplied beans (test doubles) given to the context prior to building.
37
- */
38
- private final boolean hasSuppliedBeans ;
32
+ final DBeanMap beanMap = new DBeanMap ();
39
33
40
34
/**
41
35
* The context/module name.
@@ -54,14 +48,12 @@ class DBuilder implements Builder {
54
48
55
49
private final Map <String , BeanContext > children = new LinkedHashMap <>();
56
50
57
- private final Map <Class <?>, SpyConsumer > spyMap ;
58
-
59
51
/**
60
52
* Debug of the current bean being wired - used in injection errors.
61
53
*/
62
54
private Class <?> injectTarget ;
63
55
64
- private Builder parent ;
56
+ Builder parent ;
65
57
66
58
/**
67
59
* Create a named context for non-root builders.
@@ -70,29 +62,15 @@ class DBuilder implements Builder {
70
62
this .name = name ;
71
63
this .provides = provides ;
72
64
this .dependsOn = dependsOn ;
73
- this .hasSuppliedBeans = false ;
74
- this .spyMap = null ;
75
65
}
76
66
77
67
/**
78
- * Create for the root builder with supplied beans (test doubles) .
68
+ * Create for the root builder.
79
69
*/
80
- DBuilder (List < SuppliedBean > suppliedBeans , List < SpyConsumer > spyConsumers ) {
70
+ DBuilder () {
81
71
this .name = null ;
82
72
this .provides = null ;
83
73
this .dependsOn = null ;
84
- this .hasSuppliedBeans = (suppliedBeans != null && !suppliedBeans .isEmpty ());
85
- if (hasSuppliedBeans ) {
86
- beanMap .add (suppliedBeans );
87
- }
88
- if (spyConsumers == null || spyConsumers .isEmpty ()) {
89
- spyMap = null ;
90
- } else {
91
- spyMap = new HashMap <>();
92
- for (SpyConsumer spy : spyConsumers ) {
93
- spyMap .put (spy .getType (), spy );
94
- }
95
- }
96
74
}
97
75
98
76
@ Override
@@ -117,9 +95,6 @@ public void setParent(Builder parent) {
117
95
118
96
@ Override
119
97
public boolean isAddBeanFor (Class <?> addForType , Class <?> injectTarget ) {
120
- if (hasSuppliedBeans ) {
121
- return !beanMap .isSupplied (addForType .getName ());
122
- }
123
98
if (parent == null ) {
124
99
return true ;
125
100
}
@@ -177,10 +152,8 @@ public void addChild(BeanContext child) {
177
152
@ Override
178
153
public void register (Object bean , String name , Class <?>... types ) {
179
154
if (parent != null ) {
180
- // spy consumers only exist on top level builder
181
- bean = parent .spy (bean , types );
182
- } else {
183
- bean = spy (bean , types );
155
+ // enrichment only exist on top level builder
156
+ bean = parent .enrich (bean , types );
184
157
}
185
158
beanMap .register (bean , name , types );
186
159
}
@@ -189,27 +162,11 @@ public void register(Object bean, String name, Class<?>... types) {
189
162
* Return the bean to register potentially with spy enhancement.
190
163
*/
191
164
@ Override
192
- public Object spy (Object bean , Class <?>[] types ) {
193
- if (spyMap != null ) {
194
- SpyConsumer spyConsumer = spyMap .get (typeOf (bean , types ));
195
- if (spyConsumer != null ) {
196
- // enrich/enhance the bean for spying
197
- return spyConsumer .spy (bean );
198
- }
199
- }
165
+ public Object enrich (Object bean , Class <?>[] types ) {
166
+ // only enriched by DBuilderExtn
200
167
return bean ;
201
168
}
202
169
203
- /**
204
- * Return the type to lookup for spy.
205
- */
206
- private Class <?> typeOf (Object bean , Class <?>... types ) {
207
- if (types .length > 0 ) {
208
- return types [0 ];
209
- }
210
- return bean .getClass ();
211
- }
212
-
213
170
@ Override
214
171
public void registerPrimary (Object bean , String name , Class <?>... types ) {
215
172
beanMap .registerPrimary (bean , name , types );
0 commit comments