Skip to content

Commit 3f3d1fb

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

24 files changed

+80
-80
lines changed

blackbox-test-inject/src/test/java/org/example/myapp/TestModule_serviceLoad_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ void test_underlying_mechanics() {
1919
// if (testMod.isPresent()) {
2020
// // build what is our "global test BeanScope" which we use as a parent for all tests
2121
// BeanScope parent = BeanScope.builder()
22-
// .withModules(testMod.get())
22+
// .modules(testMod.get())
2323
// .build();
2424
//
2525
// // a test creates a BeanScope with the parent of our "global test BeanScope"
26-
// BeanScope child = BeanScope.builder().withParent(parent, false).build();
26+
// BeanScope child = BeanScope.builder().parent(parent, false).build();
2727
//
2828
// HelloService helloService = child.get(HelloService.class);
2929
// assertEquals("hello+TestHelloData", helloService.hello());

inject-test/src/main/java/io/avaje/inject/test/InjectExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void beforeEach(final ExtensionContext context) {
6969
final List<MetaReader> readers = createMetaReaders(context);
7070
final BeanScopeBuilder builder = BeanScope.builder();
7171
if (globalTestScope != null) {
72-
builder.withParent(globalTestScope, false);
72+
builder.parent(globalTestScope, false);
7373
}
7474
// register mocks and spies local to this test
7575
for (MetaReader reader : readers) {

inject-test/src/main/java/io/avaje/inject/test/MetaReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ private Object captorFor(Field field) {
122122
void build(BeanScopeBuilder builder) {
123123
final BeanScopeBuilder.ForTesting forTesting = builder.forTesting();
124124
for (FieldTarget target : mocks) {
125-
forTesting.withMock(target.type(), target.name());
125+
forTesting.mock(target.type(), target.name());
126126
}
127127
for (FieldTarget target : spies) {
128-
forTesting.withSpy(target.type(), target.name());
128+
forTesting.spy(target.type(), target.name());
129129
}
130130
}
131131

inject-test/src/main/java/io/avaje/inject/test/TSBuild.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ private BeanScope build() {
7272

7373
private BeanScope buildFromModules(List<TestModule> testModules) {
7474
return BeanScope.builder()
75-
.withModules(testModules.toArray(Module[]::new))
76-
.withShutdownHook(shutdownHook)
75+
.modules(testModules.toArray(Module[]::new))
76+
.shutdownHook(shutdownHook)
7777
.build();
7878
}
7979

inject-test/src/main/java/io/avaje/inject/test/TestBeanScope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public abstract class TestBeanScope {
2121
*/
2222
public static BeanScopeBuilder builder() {
2323
BeanScope globalTestScope = init(true);
24-
return BeanScope.builder().withParent(globalTestScope, false);
24+
return BeanScope.builder().parent(globalTestScope, false);
2525
}
2626

2727
/**

inject-test/src/test/java/io/avaje/inject/xtra/ApplicationScope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ApplicationScope {
3535
private static final BeanScope appScope = init();
3636

3737
private static BeanScope init() {
38-
return BeanScope.builder().withShutdownHook(true).build();
38+
return BeanScope.builder().shutdownHook(true).build();
3939
}
4040

4141
private ApplicationScope() {

inject-test/src/test/java/org/example/coffee/BeanScopeBuilderAddTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class BeanScopeBuilderAddTest {
1818
void withModules_excludingThisOne() {
1919
TDPump testDoublePump = new TDPump();
2020
try (BeanScope context = BeanScope.builder()
21-
.withBeans(testDoublePump)
21+
.beans(testDoublePump)
2222
// our module is "org.example.coffee"
2323
// so this effectively includes no modules
24-
.withModules(new SillyModule())
24+
.modules(new SillyModule())
2525
.build()) {
2626

2727
assertThrows(NoSuchElementException.class, () -> context.get(CoffeeMaker.class));
@@ -62,8 +62,8 @@ void withModules_includeThisOne() {
6262
TDPump testDoublePump = new TDPump();
6363

6464
try (BeanScope context = BeanScope.builder()
65-
.withBeans(testDoublePump)
66-
.withModules(new org.example.ExampleModule())
65+
.beans(testDoublePump)
66+
.modules(new org.example.ExampleModule())
6767
.build()) {
6868

6969
String makeIt = context.get(CoffeeMaker.class).makeIt();
@@ -80,7 +80,7 @@ void withBean_expect_testDoublePumpUsed() {
8080
TDPump testDoublePump = new TDPump();
8181

8282
try (BeanScope context = BeanScope.builder()
83-
.withBeans(testDoublePump)
83+
.beans(testDoublePump)
8484
.build()) {
8585

8686
String makeIt = context.get(CoffeeMaker.class).makeIt();
@@ -97,7 +97,7 @@ void withMockitoMock_expect_mockUsed() {
9797
Pump mock = Mockito.mock(Pump.class);
9898

9999
try (BeanScope context = BeanScope.builder()
100-
.withBean(Pump.class, mock)
100+
.bean(Pump.class, mock)
101101
.build()) {
102102

103103
Pump pump = context.get(Pump.class);

inject-test/src/test/java/org/example/coffee/BeanScope_Builder_mockitoSpyTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void withBeans_asMocks() {
2929
Grinder grinder = mock(Grinder.class);
3030

3131
try (BeanScope context = BeanScope.builder()
32-
.withBeans(pump, grinder)
32+
.beans(pump, grinder)
3333
.build()) {
3434

3535
CoffeeMaker coffeeMaker = context.get(CoffeeMaker.class);
@@ -51,7 +51,7 @@ void withMockitoSpy_noSetup_expect_spyUsed() {
5151

5252
try (BeanScope context = BeanScope.builder()
5353
.forTesting()
54-
.withSpy(Pump.class)
54+
.spy(Pump.class)
5555
.build()) {
5656

5757
CoffeeMaker coffeeMaker = context.get(CoffeeMaker.class);
@@ -68,8 +68,8 @@ void withMockitoSpy_postLoadSetup_expect_spyUsed() {
6868

6969
try (BeanScope context = BeanScope.builder()
7070
.forTesting()
71-
.withSpy(Pump.class)
72-
.withSpy(Grinder.class)
71+
.spy(Pump.class)
72+
.spy(Grinder.class)
7373
.build()) {
7474

7575
// setup after load()
@@ -92,7 +92,7 @@ void withMockitoSpy_expect_spyUsed() {
9292

9393
try (BeanScope context = BeanScope.builder()
9494
.forTesting()
95-
.withSpy(Pump.class, pump -> {
95+
.spy(Pump.class, pump -> {
9696
// setup the spy
9797
doNothing().when(pump).pumpWater();
9898
})
@@ -116,7 +116,7 @@ void withMockitoSpy_whenPrimary_expect_spyUsed() {
116116

117117
try (BeanScope context = BeanScope.builder()
118118
.forTesting()
119-
.withSpy(PEmailer.class) // has a primary
119+
.spy(PEmailer.class) // has a primary
120120
.build()) {
121121

122122
UserOfPEmailer user = context.get(UserOfPEmailer.class);
@@ -132,7 +132,7 @@ void withMockitoSpy_whenOnlySecondary_expect_spyUsed() {
132132

133133
try (BeanScope context = BeanScope.builder()
134134
.forTesting()
135-
.withSpy(Widget.class) // only secondary
135+
.spy(Widget.class) // only secondary
136136
.build()) {
137137

138138
WidgetUser widgetUser = context.get(WidgetUser.class);
@@ -174,7 +174,7 @@ void withMockitoSpy_whenSecondary_expect_spyUsed() {
174174

175175
try (BeanScope context = BeanScope.builder()
176176
.forTesting()
177-
.withSpy(Something.class) // has a secondary and a normal
177+
.spy(Something.class) // has a secondary and a normal
178178
.build()) {
179179

180180
Unused unused = context.get(Unused.class);
@@ -198,8 +198,8 @@ void withMockitoMock_expect_mockUsed() {
198198

199199
try (BeanScope context = BeanScope.builder()
200200
.forTesting()
201-
.withMock(Pump.class)
202-
.withMock(Grinder.class, grinder -> {
201+
.mock(Pump.class)
202+
.mock(Grinder.class, grinder -> {
203203
// setup the mock
204204
when(grinder.grindBeans()).thenReturn("stub response");
205205
mock.set(grinder);

inject-test/src/test/java/org/example/coffee/CoffeeMakerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void makeIt_via_SystemContext() {
3636
@Test
3737
void makeIt_via_BootContext_withNoShutdownHook() {
3838
try (BeanScope context = BeanScope.builder()
39-
.withShutdownHook(false)
39+
.shutdownHook(false)
4040
.build()) {
4141

4242
String makeIt = context.get(CoffeeMaker.class).makeIt();

inject-test/src/test/java/org/example/coffee/ExtensionExample.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
class ExtensionExample {
99

10-
private final List<Class<?>> withMocks;
11-
private final List<Class> withSpies;
10+
private final List<Class<?>> mocks;
11+
private final List<Class> spies;
1212

13-
ExtensionExample(List<Class<?>> withMocks, List<Class> withSpies) {
14-
this.withMocks = withMocks;
15-
this.withSpies = withSpies;
13+
ExtensionExample(List<Class<?>> mocks, List<Class> spies) {
14+
this.mocks = mocks;
15+
this.spies = spies;
1616
}
1717

1818
BeanScope build() {
1919
BeanScopeBuilder.ForTesting bootContext = BeanScope.builder().forTesting();
20-
withMocks.forEach(bootContext::withMock);
21-
withSpies.forEach(bootContext::withSpy);
20+
mocks.forEach(bootContext::mock);
21+
spies.forEach(bootContext::spy);
2222
return bootContext.build();
2323
}
2424

inject-test/src/test/java/org/example/coffee/ExtensionExampleTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ void checkForCompilerWarningsOnly_notATestThatRuns() {
2323

2424
BeanScopeBuilder bootContext = BeanScope.builder()
2525
.forTesting()
26-
.withSpy(cls0)
27-
.withSpy(cls1)
28-
.withMock(cls0)
29-
.withMock(cls1);
26+
.spy(cls0)
27+
.spy(cls1)
28+
.mock(cls0)
29+
.mock(cls1);
3030

3131
assertNotNull(context);
3232
assertNotNull(bootContext);

inject-test/src/test/java/org/example/coffee/fruit/AppleServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AppleServiceTest {
1414
public void test_spyWithFieldInjection() {
1515

1616
BeanScopeBuilder contextBuilder = BeanScope.builder();
17-
contextBuilder.forTesting().withSpy(AppleService.class);
17+
contextBuilder.forTesting().spy(AppleService.class);
1818

1919
try (BeanScope beanScope = contextBuilder.build()) {
2020

inject-test/src/test/java/org/example/coffee/generic/HazManagerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void find_when_allWired() {
2222
public void find_with_mockHaz() {
2323
try (BeanScope context = BeanScope.builder()
2424
.forTesting()
25-
.withMock(HazRepo.class)
25+
.mock(HazRepo.class)
2626
.build()) {
2727

2828
HazManager hazManager = context.get(HazManager.class);
@@ -36,7 +36,7 @@ public void find_with_mockHaz() {
3636
public void find_with_stubHazUsingMockito() {
3737
try (BeanScope context = BeanScope.builder()
3838
.forTesting()
39-
.withMock(HazRepo.class, hazRepo -> {
39+
.mock(HazRepo.class, hazRepo -> {
4040
when(hazRepo.findById(anyLong())).thenReturn(new Haz(-23L));
4141
})
4242
.build()) {
@@ -53,7 +53,7 @@ public void withBean_usingGenericType() {
5353
TDFoo testDouble = new TDFoo();
5454

5555
try (BeanScope context = BeanScope.builder()
56-
.withBean(HazRepo$DI.TYPE_RepositoryHazLong, testDouble)
56+
.bean(HazRepo$DI.TYPE_RepositoryHazLong, testDouble)
5757
.build()) {
5858

5959
HazManager hazManager = context.get(HazManager.class);
@@ -68,7 +68,7 @@ public void find_with_testDouble() {
6868
TDHazRepo testDouble = new TDHazRepo();
6969

7070
try (BeanScope context = BeanScope.builder()
71-
.withBeans(testDouble)
71+
.beans(testDouble)
7272
.build()) {
7373

7474
HazManager hazManager = context.get(HazManager.class);

inject-test/src/test/java/org/example/coffee/qualifier/StoreManagerWithSetterQualifierTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ void redStore() {
1919
@Test
2020
void namedTestDouble() {
2121
try (BeanScope context = BeanScope.builder()
22-
.withBean("Blue", SomeStore.class, () -> "TD Blue")
23-
.withBean("Green", SomeStore.class, () -> "TD Green")
22+
.bean("Blue", SomeStore.class, () -> "TD Blue")
23+
.bean("Green", SomeStore.class, () -> "TD Green")
2424
.build()) {
2525

2626
StoreManagerWithSetterQualifier manager = context.get(StoreManagerWithSetterQualifier.class);
@@ -32,7 +32,7 @@ void namedTestDouble() {
3232
@Test
3333
void namedTestDouble_expect_otherNamedStillWired() {
3434
try (BeanScope context = BeanScope.builder()
35-
.withBean("Blue", SomeStore.class, () -> "TD Blue Only")
35+
.bean("Blue", SomeStore.class, () -> "TD Blue Only")
3636
// with GreenStore still wired
3737
.build()) {
3838

inject-test/src/test/java/org/example/custom/CustomScopeTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ void customScopeWithParent() {
2525
LocalExt ext = new LocalExt();
2626

2727
try (BeanScope beanScope = BeanScope.builder()
28-
.withParent(parentScope)
29-
.withModules(new MyCustomModule(ext))
28+
.parent(parentScope)
29+
.modules(new MyCustomModule(ext))
3030
.build()) {
3131

3232
final CoffeeMaker coffeeMaker = beanScope.get(CoffeeMaker.class);
@@ -50,8 +50,8 @@ void buildSimpleCustomScope() {
5050
CoffeeMaker suppliedCoffeeMaker = Mockito.mock(CoffeeMaker.class);
5151

5252
try (BeanScope beanScope = BeanScope.builder()
53-
.withModules(new MyCustomModule(ext))
54-
.withBean(CoffeeMaker.class, suppliedCoffeeMaker)
53+
.modules(new MyCustomModule(ext))
54+
.bean(CoffeeMaker.class, suppliedCoffeeMaker)
5555
.build()) {
5656

5757
final CustomBean bean = beanScope.get(CustomBean.class);
@@ -74,8 +74,8 @@ void customScopeAll() {
7474
CoffeeMaker suppliedCoffeeMaker = Mockito.mock(CoffeeMaker.class);
7575

7676
try (BeanScope beanScope = BeanScope.builder()
77-
.withModules(new MyCustomModule(ext))
78-
.withBean(CoffeeMaker.class, suppliedCoffeeMaker)
77+
.modules(new MyCustomModule(ext))
78+
.bean(CoffeeMaker.class, suppliedCoffeeMaker)
7979
.build()) {
8080

8181
// includes the 2 supplied beans

inject-test/src/test/java/org/example/custom3/ParentScopeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class ParentScopeTest {
1717
void parentScope() {
1818

1919
final BeanScope parent = BeanScope.builder()
20-
.withModules(new OtherModule())
20+
.modules(new OtherModule())
2121
.build();
2222

2323
final BeanScope scope = BeanScope.builder()
24-
.withModules(new MyThreeModule())
25-
.withParent(parent)
24+
.modules(new MyThreeModule())
25+
.parent(parent)
2626
.build();
2727

2828
// factory for custom scope

inject-test/src/test/java/org/example/custom4/LinuxScopeTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void test_via_nested_scopes() {
1414

1515
// our top scope
1616
try (BeanScope buildScope = BeanScope.builder()
17-
.withModules(buildModule)
17+
.modules(buildModule)
1818
.build()) {
1919

2020
Build build = buildScope.get(Build.class);
@@ -25,8 +25,8 @@ void test_via_nested_scopes() {
2525

2626
// our middle scope (depends on top scope)
2727
try (BeanScope machineScope = BeanScope.builder()
28-
.withParent(buildScope)
29-
.withModules(machineModule)
28+
.parent(buildScope)
29+
.modules(machineModule)
3030
.build()) {
3131

3232
MachineOne machineOne = machineScope.get(MachineOne.class);
@@ -37,8 +37,8 @@ void test_via_nested_scopes() {
3737
// this is our case for Issue 171 where LinuxOne depends on Build
3838
// which is transitively supplied via MachineScope
3939
try (BeanScope linuxScope = BeanScope.builder()
40-
.withParent(machineScope)
41-
.withModules(new LinuxModule())
40+
.parent(machineScope)
41+
.modules(new LinuxModule())
4242
.build()) {
4343

4444
MachineOne machineOne2 = linuxScope.get(MachineOne.class);
@@ -64,7 +64,7 @@ void test_via_flattened_module_structure() {
6464
// our 'flattened' bean scope
6565
try (BeanScope flatScope = BeanScope.builder()
6666
// all our scope modules
67-
.withModules(new BuildModule(buildExternal), new MachineModule(machineExternal), new LinuxModule())
67+
.modules(new BuildModule(buildExternal), new MachineModule(machineExternal), new LinuxModule())
6868
.build()) {
6969

7070
Build build = flatScope.get(Build.class);

inject-test/src/test/java/org/example/customext0/Ext0ScopeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Ext0ScopeTest {
1111
void wire() {
1212

1313
final BeanScope scope = BeanScope.builder()
14-
.withModules(new Ext0Module(new If0(), new Ext0conc()))
14+
.modules(new Ext0Module(new If0(), new Ext0conc()))
1515
.build();
1616

1717
final Ext0Other other = scope.get(Ext0Other.class);

0 commit comments

Comments
 (0)