Skip to content

Commit 37e95bc

Browse files
committed
#207 - Rename "with" methods with deprecate. e.g. migrate withBean() -> bean(), withSpy() -> spy()
1 parent 29343fc commit 37e95bc

File tree

5 files changed

+179
-59
lines changed

5 files changed

+179
-59
lines changed

inject/src/main/java/io/avaje/inject/BeanScope.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@
5858
*
5959
* }</pre>
6060
* <p>
61-
* When we build the BeanScope provide the dependency via {@link BeanScopeBuilder#withBean(Class, Object)}.
61+
* When we build the BeanScope provide the dependency via {@link BeanScopeBuilder#bean(Class, Object)}.
6262
*
6363
* <pre>{@code
6464
*
6565
* // provide external dependencies ...
6666
* Pump pump = ...
6767
*
6868
* try (BeanScope scope = BeanScope.builder()
69-
* .withBean(Pump.class, pump)
69+
* .bean(Pump.class, pump)
7070
* .build()) {
7171
*
7272
* CoffeeMaker coffeeMaker = context.get(CoffeeMaker.class);

inject/src/main/java/io/avaje/inject/BeanScopeBuilder.java

Lines changed: 150 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Pump pump = ...
1919
*
2020
* BeanScope scope = BeanScope.builder()
21-
* .withBean(pump)
21+
* .bean(pump)
2222
* .build();
2323
*
2424
* CoffeeMaker coffeeMaker = scope.get(CoffeeMaker.class);
@@ -41,7 +41,7 @@ public interface BeanScopeBuilder {
4141
* // automatically closed via try with resources
4242
*
4343
* BeanScope scope = BeanScope.builder()
44-
* .withShutdownHook(true)
44+
* .shutdownHook(true)
4545
* .build());
4646
*
4747
* // on JVM shutdown the preDestroy lifecycle methods are executed
@@ -50,7 +50,15 @@ public interface BeanScopeBuilder {
5050
*
5151
* @return This BeanScopeBuilder
5252
*/
53-
BeanScopeBuilder withShutdownHook(boolean shutdownHook);
53+
BeanScopeBuilder shutdownHook(boolean shutdownHook);
54+
55+
/**
56+
* Deprecated - migrate to shutdownHook().
57+
*/
58+
@Deprecated
59+
default BeanScopeBuilder withShutdownHook(boolean shutdownHook) {
60+
return shutdownHook(shutdownHook);
61+
}
5462

5563
/**
5664
* Specify the modules to include in dependency injection.
@@ -63,7 +71,7 @@ public interface BeanScopeBuilder {
6371
* <pre>{@code
6472
*
6573
* BeanScope scope = BeanScope.builder()
66-
* .withModules(new CustomModule())
74+
* .modules(new CustomModule())
6775
* .build());
6876
*
6977
* CoffeeMaker coffeeMaker = scope.get(CoffeeMaker.class);
@@ -74,7 +82,15 @@ public interface BeanScopeBuilder {
7482
* @param modules The modules that we want to include in dependency injection.
7583
* @return This BeanScopeBuilder
7684
*/
77-
BeanScopeBuilder withModules(Module... modules);
85+
BeanScopeBuilder modules(Module... modules);
86+
87+
/**
88+
* Deprecated - migrate to modules()
89+
*/
90+
@Deprecated
91+
default BeanScopeBuilder withModules(Module... modules) {
92+
return modules(modules);
93+
}
7894

7995
/**
8096
* Supply a bean to the scope that will be used instead of any
@@ -91,7 +107,7 @@ public interface BeanScopeBuilder {
91107
* Grinder grinder = ...
92108
*
93109
* BeanScope scope = BeanScope.builder()
94-
* .withBeans(pump, grinder)
110+
* .beans(pump, grinder)
95111
* .build();
96112
*
97113
* CoffeeMaker coffeeMaker = scope.get(CoffeeMaker.class);
@@ -103,7 +119,15 @@ public interface BeanScopeBuilder {
103119
* for the bean or the interface(s) it implements
104120
* @return This BeanScopeBuilder
105121
*/
106-
BeanScopeBuilder withBeans(Object... beans);
122+
BeanScopeBuilder beans(Object... beans);
123+
124+
/**
125+
* Deprecated - migrate to beans().
126+
*/
127+
@Deprecated
128+
default BeanScopeBuilder withBeans(Object... beans) {
129+
return beans(beans);
130+
}
107131

108132
/**
109133
* Add a supplied bean instance with the given injection type (typically an interface type).
@@ -113,7 +137,7 @@ public interface BeanScopeBuilder {
113137
* Pump externalDependency = ...
114138
*
115139
* try (BeanScope scope = BeanScope.builder()
116-
* .withBean(Pump.class, externalDependency)
140+
* .bean(Pump.class, externalDependency)
117141
* .build()) {
118142
*
119143
* CoffeeMaker coffeeMaker = scope.get(CoffeeMaker.class);
@@ -128,7 +152,15 @@ public interface BeanScopeBuilder {
128152
* @param type The dependency injection type this bean is target for
129153
* @param bean The supplied bean instance to use for injection
130154
*/
131-
<D> BeanScopeBuilder withBean(Class<D> type, D bean);
155+
<D> BeanScopeBuilder bean(Class<D> type, D bean);
156+
157+
/**
158+
* Deprecated - migrate to bean().
159+
*/
160+
@Deprecated
161+
default <D> BeanScopeBuilder withBean(Class<D> type, D bean) {
162+
return bean(type, bean);
163+
}
132164

133165
/**
134166
* Add a supplied bean instance with the given name and injection type.
@@ -137,7 +169,15 @@ public interface BeanScopeBuilder {
137169
* @param type The dependency injection type this bean is target for
138170
* @param bean The supplied bean instance to use for injection
139171
*/
140-
<D> BeanScopeBuilder withBean(String name, Class<D> type, D bean);
172+
<D> BeanScopeBuilder bean(String name, Class<D> type, D bean);
173+
174+
/**
175+
* Deprecated - migrate to bean().
176+
*/
177+
@Deprecated
178+
default <D> BeanScopeBuilder withBean(String name, Class<D> type, D bean) {
179+
return bean(name, type, bean);
180+
}
141181

142182
/**
143183
* Add a supplied bean instance with the given name and generic type.
@@ -146,23 +186,47 @@ public interface BeanScopeBuilder {
146186
* @param type The dependency injection type this bean is target for
147187
* @param bean The supplied bean instance to use for injection
148188
*/
149-
<D> BeanScopeBuilder withBean(String name, Type type, D bean);
189+
<D> BeanScopeBuilder bean(String name, Type type, D bean);
190+
191+
/**
192+
* Deprecated - migrate to bean().
193+
*/
194+
@Deprecated
195+
default <D> BeanScopeBuilder withBean(String name, Type type, D bean) {
196+
return bean(name, type, bean);
197+
}
150198

151199
/**
152200
* Add a supplied bean instance with a generic type.
153201
*
154202
* @param type The dependency injection type this bean is target for
155203
* @param bean The supplied bean instance to use for injection
156204
*/
157-
<D> BeanScopeBuilder withBean(Type type, D bean);
205+
<D> BeanScopeBuilder bean(Type type, D bean);
206+
207+
/**
208+
* Deprecated - migrate to bean().
209+
*/
210+
@Deprecated
211+
default <D> BeanScopeBuilder withBean(Type type, D bean) {
212+
return bean(type, bean);
213+
}
158214

159215
/**
160216
* Use the given BeanScope as the parent. This becomes an additional
161217
* source of beans that can be wired and accessed in this scope.
162218
*
163219
* @param parent The BeanScope that acts as the parent
164220
*/
165-
BeanScopeBuilder withParent(BeanScope parent);
221+
BeanScopeBuilder parent(BeanScope parent);
222+
223+
/**
224+
* Deprecated - migrate to parent().
225+
*/
226+
@Deprecated
227+
default BeanScopeBuilder withParent(BeanScope parent) {
228+
return parent(parent);
229+
}
166230

167231
/**
168232
* Use the given BeanScope as the parent additionally specifying if beans
@@ -172,7 +236,15 @@ public interface BeanScopeBuilder {
172236
* @param parentOverride When false do not add beans that already exist on the parent.
173237
* When true add beans regardless of whether they exist in the parent scope.
174238
*/
175-
BeanScopeBuilder withParent(BeanScope parent, boolean parentOverride);
239+
BeanScopeBuilder parent(BeanScope parent, boolean parentOverride);
240+
241+
/**
242+
* Deprecated - migrate to parent().
243+
*/
244+
@Deprecated
245+
default BeanScopeBuilder withParent(BeanScope parent, boolean parentOverride) {
246+
return parent(parent, parentOverride);
247+
}
176248

177249
/**
178250
* Extend the builder to support testing using mockito with
@@ -206,8 +278,8 @@ interface ForTesting extends BeanScopeBuilder {
206278
*
207279
* try (BeanScope scope = BeanScope.builder()
208280
* .forTesting()
209-
* .withMock(Pump.class)
210-
* .withMock(Grinder.class)
281+
* .mock(Pump.class)
282+
* .mock(Grinder.class)
211283
* .build()) {
212284
*
213285
*
@@ -221,7 +293,15 @@ interface ForTesting extends BeanScopeBuilder {
221293
*
222294
* }</pre>
223295
*/
224-
BeanScopeBuilder.ForTesting withMock(Class<?> type);
296+
BeanScopeBuilder.ForTesting mock(Class<?> type);
297+
298+
/**
299+
* Deprecated - migrate to mock().
300+
*/
301+
@Deprecated
302+
default BeanScopeBuilder.ForTesting withMock(Class<?> type) {
303+
return mock(type);
304+
}
225305

226306
/**
227307
* Register as a Mockito mock with a qualifier name.
@@ -230,16 +310,24 @@ interface ForTesting extends BeanScopeBuilder {
230310
*
231311
* try (BeanScope scope = BeanScope.builder()
232312
* .forTesting()
233-
* .withMock(Store.class, "red")
234-
* .withMock(Store.class, "blue")
313+
* .mock(Store.class, "red")
314+
* .mock(Store.class, "blue")
235315
* .build()) {
236316
*
237317
* ...
238318
* }
239319
*
240320
* }</pre>
241321
*/
242-
BeanScopeBuilder.ForTesting withMock(Class<?> type, String name);
322+
BeanScopeBuilder.ForTesting mock(Class<?> type, String name);
323+
324+
/**
325+
* Deprecated - migrate to mock().
326+
*/
327+
@Deprecated
328+
default BeanScopeBuilder.ForTesting withMock(Class<?> type, String name) {
329+
return mock(type, name);
330+
}
243331

244332
/**
245333
* Use a mockito mock when injecting this bean type additionally
@@ -249,8 +337,8 @@ interface ForTesting extends BeanScopeBuilder {
249337
*
250338
* try (BeanScope scope = BeanScope.builder()
251339
* .forTesting()
252-
* .withMock(Pump.class)
253-
* .withMock(Grinder.class, grinder -> {
340+
* .mock(Pump.class)
341+
* .mock(Grinder.class, grinder -> {
254342
*
255343
* // setup the mock
256344
* when(grinder.grindBeans()).thenReturn("stub response");
@@ -268,7 +356,15 @@ interface ForTesting extends BeanScopeBuilder {
268356
*
269357
* }</pre>
270358
*/
271-
<D> BeanScopeBuilder.ForTesting withMock(Class<D> type, Consumer<D> consumer);
359+
<D> BeanScopeBuilder.ForTesting mock(Class<D> type, Consumer<D> consumer);
360+
361+
/**
362+
* Deprecated - migrate to mock().
363+
*/
364+
@Deprecated
365+
default <D> BeanScopeBuilder.ForTesting withMock(Class<D> type, Consumer<D> consumer) {
366+
return mock(type, consumer);
367+
}
272368

273369
/**
274370
* Use a mockito spy when injecting this bean type.
@@ -277,7 +373,7 @@ interface ForTesting extends BeanScopeBuilder {
277373
*
278374
* try (BeanScope scope = BeanScope.builder()
279375
* .forTesting()
280-
* .withSpy(Pump.class)
376+
* .spy(Pump.class)
281377
* .build()) {
282378
*
283379
* // setup spy here ...
@@ -294,7 +390,15 @@ interface ForTesting extends BeanScopeBuilder {
294390
*
295391
* }</pre>
296392
*/
297-
BeanScopeBuilder.ForTesting withSpy(Class<?> type);
393+
BeanScopeBuilder.ForTesting spy(Class<?> type);
394+
395+
/**
396+
* Deprecated - migrate to spy().
397+
*/
398+
@Deprecated
399+
default BeanScopeBuilder.ForTesting withSpy(Class<?> type) {
400+
return spy(type);
401+
}
298402

299403
/**
300404
* Register a Mockito spy with a qualifier name.
@@ -303,16 +407,24 @@ interface ForTesting extends BeanScopeBuilder {
303407
*
304408
* try (BeanScope scope = BeanScope.builder()
305409
* .forTesting()
306-
* .withSpy(Store.class, "red")
307-
* .withSpy(Store.class, "blue")
410+
* .spy(Store.class, "red")
411+
* .spy(Store.class, "blue")
308412
* .build()) {
309413
*
310414
* ...
311415
* }
312416
*
313417
* }</pre>
314418
*/
315-
BeanScopeBuilder.ForTesting withSpy(Class<?> type, String name);
419+
BeanScopeBuilder.ForTesting spy(Class<?> type, String name);
420+
421+
/**
422+
* Deprecated - migrate to spy().
423+
*/
424+
@Deprecated
425+
default BeanScopeBuilder.ForTesting withSpy(Class<?> type, String name) {
426+
return spy(type, name);
427+
}
316428

317429
/**
318430
* Use a mockito spy when injecting this bean type additionally
@@ -322,7 +434,7 @@ interface ForTesting extends BeanScopeBuilder {
322434
*
323435
* try (BeanScope scope = BeanScope.builder()
324436
* .forTesting()
325-
* .withSpy(Pump.class, pump -> {
437+
* .spy(Pump.class, pump -> {
326438
* // setup the spy
327439
* doNothing().when(pump).pumpWater();
328440
* })
@@ -342,7 +454,15 @@ interface ForTesting extends BeanScopeBuilder {
342454
*
343455
* }</pre>
344456
*/
345-
<D> BeanScopeBuilder.ForTesting withSpy(Class<D> type, Consumer<D> consumer);
457+
<D> BeanScopeBuilder.ForTesting spy(Class<D> type, Consumer<D> consumer);
458+
459+
/**
460+
* Deprecated - migrate to spy().
461+
*/
462+
@Deprecated
463+
default <D> BeanScopeBuilder.ForTesting withSpy(Class<D> type, Consumer<D> consumer) {
464+
return spy(type, consumer);
465+
}
346466

347467
}
348468
}

0 commit comments

Comments
 (0)