Skip to content

Commit 29343fc

Browse files
committed
#206 - Add BeanScope.builder() to replace BeanScope.newBuilder() with deprecation.
1 parent 59d752e commit 29343fc

File tree

58 files changed

+134
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+134
-129
lines changed

blackbox-test-inject/src/main/java/org/example/myapp/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class Main {
66

77
public static void main(String[] args) {
88

9-
BeanScope beanScope = BeanScope.newBuilder().build();
9+
BeanScope beanScope = BeanScope.builder().build();
1010

1111
HelloService helloService = beanScope.get(HelloService.class);
1212
String greeting = helloService.hello();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ExampleServiceTest {
1010

1111
@Test
1212
void exercise() {
13-
try (BeanScope beanScope = BeanScope.newBuilder().build()) {
13+
try (BeanScope beanScope = BeanScope.builder().build()) {
1414
ExampleService exampleService = beanScope.get(ExampleService.class);
1515

1616
exampleService.other("foo", 42);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HelloServiceTest {
2020
@Test
2121
void basic() throws IOException {
2222
// just wire everything with no test scope, mocks etc
23-
BeanScope beanScope = BeanScope.newBuilder().build();
23+
BeanScope beanScope = BeanScope.builder().build();
2424

2525
HelloService helloService = beanScope.get(HelloService.class);
2626
assertEquals("bazz foo 42", helloService.bazz("foo", 42));
@@ -30,7 +30,7 @@ void basic() throws IOException {
3030
@Test
3131
void skip() {
3232
// just wire everything with no test scope, mocks etc
33-
BeanScope beanScope = BeanScope.newBuilder().build();
33+
BeanScope beanScope = BeanScope.builder().build();
3434

3535
HelloService helloService = beanScope.get(HelloService.class);
3636
String result = helloService.skipExample("echo me back");
@@ -39,7 +39,7 @@ void skip() {
3939

4040
@Test
4141
void aspect_multiInvoke() {
42-
BeanScope beanScope = BeanScope.newBuilder().build();
42+
BeanScope beanScope = BeanScope.builder().build();
4343

4444
MyMultiInvokeAspect aspect = beanScope.get(MyMultiInvokeAspect.class);
4545
HelloService helloService = beanScope.get(HelloService.class);
@@ -51,7 +51,7 @@ void aspect_multiInvoke() {
5151

5252
@Test
5353
void aspect_checkedRunnable() throws IOException, ClassNotFoundException {
54-
BeanScope beanScope = BeanScope.newBuilder().build();
54+
BeanScope beanScope = BeanScope.builder().build();
5555

5656
MyAroundAspect aspect = beanScope.get(MyAroundAspect.class);
5757
HelloService helloService = beanScope.get(HelloService.class);
@@ -67,7 +67,7 @@ void aspect_checkedRunnable() throws IOException, ClassNotFoundException {
6767

6868
@Test
6969
void aspect_throwingUndeclaredException_expect_InvocationException() {
70-
BeanScope beanScope = BeanScope.newBuilder().build();
70+
BeanScope beanScope = BeanScope.builder().build();
7171

7272
HelloService helloService = beanScope.get(HelloService.class);
7373

@@ -80,7 +80,7 @@ void aspect_throwingUndeclaredException_expect_InvocationException() {
8080

8181
@Test
8282
void aspect_appCodeThrowingUnchecked_expect_InvocationException() {
83-
BeanScope beanScope = BeanScope.newBuilder().build();
83+
BeanScope beanScope = BeanScope.builder().build();
8484

8585
HelloService helloService = beanScope.get(HelloService.class);
8686

@@ -92,7 +92,7 @@ void aspect_appCodeThrowingUnchecked_expect_InvocationException() {
9292

9393
@Test
9494
void aspect_appCodeThrowingDeclared_expect_declaredException() {
95-
BeanScope beanScope = BeanScope.newBuilder().build();
95+
BeanScope beanScope = BeanScope.builder().build();
9696

9797
HelloService helloService = beanScope.get(HelloService.class);
9898

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class OtherServiceProxyTest {
1313
@Test
1414
void proxyMethodInvocation() {
1515

16-
BeanScope beanScope = BeanScope.newBuilder().build();
16+
BeanScope beanScope = BeanScope.builder().build();
1717
OtherService otherService = beanScope.get(OtherService.class);
1818

1919
String result = otherService.other("foo", 42);

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
@@ -18,12 +18,12 @@ void test_underlying_mechanics() {
1818

1919
// if (testMod.isPresent()) {
2020
// // build what is our "global test BeanScope" which we use as a parent for all tests
21-
// BeanScope parent = BeanScope.newBuilder()
21+
// BeanScope parent = BeanScope.builder()
2222
// .withModules(testMod.get())
2323
// .build();
2424
//
2525
// // a test creates a BeanScope with the parent of our "global test BeanScope"
26-
// BeanScope child = BeanScope.newBuilder().withParent(parent, false).build();
26+
// BeanScope child = BeanScope.builder().withParent(parent, false).build();
2727
//
2828
// HelloService helloService = child.get(HelloService.class);
2929
// assertEquals("hello+TestHelloData", helloService.hello());

blackbox-test-inject/src/test/java/org/example/myapp/r4j/Resilience4J_retry_Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Resilience4J_retry_Test {
1414
void retry_test() {
1515

1616
MyExample myExample;
17-
try (BeanScope beanScope = BeanScope.newBuilder().build()) {
17+
try (BeanScope beanScope = BeanScope.builder().build()) {
1818
myExample = beanScope.get(MyExample.class);
1919

2020
assertThatThrownBy(myExample::doingItWithRetry)
@@ -31,7 +31,7 @@ void retry_test() {
3131
void retry_fallback_test() {
3232

3333
MyExample myExample;
34-
try (BeanScope beanScope = BeanScope.newBuilder().build()) {
34+
try (BeanScope beanScope = BeanScope.builder().build()) {
3535
myExample = beanScope.get(MyExample.class);
3636

3737
String result = myExample.retryWithFallback();
@@ -46,7 +46,7 @@ void retry_fallback_test() {
4646
void retry_fallback_throwable_test() {
4747

4848
MyExample myExample;
49-
try (BeanScope beanScope = BeanScope.newBuilder().build()) {
49+
try (BeanScope beanScope = BeanScope.builder().build()) {
5050
myExample = beanScope.get(MyExample.class);
5151

5252
String result = myExample.retry2("foo", 45);

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
@@ -67,7 +67,7 @@ private void initialiseGlobalTestScope(ExtensionContext context) {
6767
@Override
6868
public void beforeEach(final ExtensionContext context) {
6969
final List<MetaReader> readers = createMetaReaders(context);
70-
final BeanScopeBuilder builder = BeanScope.newBuilder();
70+
final BeanScopeBuilder builder = BeanScope.builder();
7171
if (globalTestScope != null) {
7272
builder.withParent(globalTestScope, false);
7373
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private BeanScope build() {
7171
}
7272

7373
private BeanScope buildFromModules(List<TestModule> testModules) {
74-
return BeanScope.newBuilder()
74+
return BeanScope.builder()
7575
.withModules(testModules.toArray(Module[]::new))
7676
.withShutdownHook(shutdownHook)
7777
.build();

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.newBuilder().withParent(globalTestScope, false);
24+
return BeanScope.builder().withParent(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.newBuilder().withShutdownHook(true).build();
38+
return BeanScope.builder().withShutdownHook(true).build();
3939
}
4040

4141
private ApplicationScope() {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class SystemContextTest {
2121

2222
@Test
2323
public void getBeansByPriority() {
24-
try (BeanScope context = BeanScope.newBuilder().build()) {
24+
try (BeanScope context = BeanScope.builder().build()) {
2525
final List<BaseIface> beans = context.listByPriority(BaseIface.class);
2626
assertThat(beans).hasSize(3);
2727

@@ -33,7 +33,7 @@ public void getBeansByPriority() {
3333

3434
@Test
3535
public void getBeansByPriority_withAnnotation() {
36-
try (BeanScope context = BeanScope.newBuilder().build()) {
36+
try (BeanScope context = BeanScope.builder().build()) {
3737
final List<Somei> beans = context.listByPriority(Somei.class, Priority.class);
3838
assertThat(beans).hasSize(3);
3939

@@ -45,7 +45,7 @@ public void getBeansByPriority_withAnnotation() {
4545

4646
@Test
4747
public void getBeansUnsorted_withPriority() {
48-
try (BeanScope context = BeanScope.newBuilder().build()) {
48+
try (BeanScope context = BeanScope.builder().build()) {
4949
final List<Somei> beans = context.list(Somei.class);
5050
assertThat(beans).hasSize(3);
5151
// can't assert bean order
@@ -54,7 +54,7 @@ public void getBeansUnsorted_withPriority() {
5454

5555
@Test
5656
public void getBeansWithAnnotation() {
57-
try (BeanScope context = BeanScope.newBuilder().build()) {
57+
try (BeanScope context = BeanScope.builder().build()) {
5858
final List<Object> beans = context.listByAnnotation(Fruit.class);
5959
assertThat(beans).hasSize(2);
6060
}

inject-test/src/test/java/org/example/autonamed/MyAutoNameTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MyAutoNameTest {
1010
@Test
1111
void impliedNames_multiple() {
1212

13-
try (final BeanScope beanScope = BeanScope.newBuilder().build()) {
13+
try (final BeanScope beanScope = BeanScope.builder().build()) {
1414

1515
final MyAutoB2 myAutoName = beanScope.get(MyAutoB2.class);
1616
assertThat(myAutoName.one()).isEqualTo("oneB2");
@@ -31,7 +31,7 @@ void impliedNames_multiple() {
3131
@Test
3232
void test() {
3333

34-
try (final BeanScope beanScope = BeanScope.newBuilder().build()) {
34+
try (final BeanScope beanScope = BeanScope.builder().build()) {
3535

3636
final MyAutoName myAutoName = beanScope.get(MyAutoName.class);
3737
assertThat(myAutoName.who()).isEqualTo("one");

inject-test/src/test/java/org/example/closable/ShouldCloseAutoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ShouldCloseAutoTest {
1111
void test_closable() {
1212

1313
ShouldCloseAuto shouldCloseAuto;
14-
try (final BeanScope scope = BeanScope.newBuilder().build()) {
14+
try (final BeanScope scope = BeanScope.builder().build()) {
1515
shouldCloseAuto = scope.get(ShouldCloseAuto.class);
1616
}
1717

@@ -22,7 +22,7 @@ void test_closable() {
2222
void test_autoCloseable() {
2323

2424
ShouldCloseAuto2 shouldCloseAuto;
25-
try (final BeanScope scope = BeanScope.newBuilder().build()) {
25+
try (final BeanScope scope = BeanScope.builder().build()) {
2626
shouldCloseAuto = scope.get(ShouldCloseAuto2.class);
2727
}
2828

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BeanScopeBuilderAddTest {
1717
@Test
1818
void withModules_excludingThisOne() {
1919
TDPump testDoublePump = new TDPump();
20-
try (BeanScope context = BeanScope.newBuilder()
20+
try (BeanScope context = BeanScope.builder()
2121
.withBeans(testDoublePump)
2222
// our module is "org.example.coffee"
2323
// so this effectively includes no modules
@@ -61,7 +61,7 @@ void withModules_includeThisOne() {
6161

6262
TDPump testDoublePump = new TDPump();
6363

64-
try (BeanScope context = BeanScope.newBuilder()
64+
try (BeanScope context = BeanScope.builder()
6565
.withBeans(testDoublePump)
6666
.withModules(new org.example.ExampleModule())
6767
.build()) {
@@ -79,7 +79,7 @@ void withBean_expect_testDoublePumpUsed() {
7979

8080
TDPump testDoublePump = new TDPump();
8181

82-
try (BeanScope context = BeanScope.newBuilder()
82+
try (BeanScope context = BeanScope.builder()
8383
.withBeans(testDoublePump)
8484
.build()) {
8585

@@ -96,7 +96,7 @@ void withMockitoMock_expect_mockUsed() {
9696

9797
Pump mock = Mockito.mock(Pump.class);
9898

99-
try (BeanScope context = BeanScope.newBuilder()
99+
try (BeanScope context = BeanScope.builder()
100100
.withBean(Pump.class, mock)
101101
.build()) {
102102

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

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

31-
try (BeanScope context = BeanScope.newBuilder()
31+
try (BeanScope context = BeanScope.builder()
3232
.withBeans(pump, grinder)
3333
.build()) {
3434

@@ -49,7 +49,7 @@ void withBeans_asMocks() {
4949
@Test
5050
void withMockitoSpy_noSetup_expect_spyUsed() {
5151

52-
try (BeanScope context = BeanScope.newBuilder()
52+
try (BeanScope context = BeanScope.builder()
5353
.forTesting()
5454
.withSpy(Pump.class)
5555
.build()) {
@@ -66,7 +66,7 @@ void withMockitoSpy_noSetup_expect_spyUsed() {
6666
@Test
6767
void withMockitoSpy_postLoadSetup_expect_spyUsed() {
6868

69-
try (BeanScope context = BeanScope.newBuilder()
69+
try (BeanScope context = BeanScope.builder()
7070
.forTesting()
7171
.withSpy(Pump.class)
7272
.withSpy(Grinder.class)
@@ -90,7 +90,7 @@ void withMockitoSpy_postLoadSetup_expect_spyUsed() {
9090
@Test
9191
void withMockitoSpy_expect_spyUsed() {
9292

93-
try (BeanScope context = BeanScope.newBuilder()
93+
try (BeanScope context = BeanScope.builder()
9494
.forTesting()
9595
.withSpy(Pump.class, pump -> {
9696
// setup the spy
@@ -114,7 +114,7 @@ void withMockitoSpy_expect_spyUsed() {
114114
@Test
115115
void withMockitoSpy_whenPrimary_expect_spyUsed() {
116116

117-
try (BeanScope context = BeanScope.newBuilder()
117+
try (BeanScope context = BeanScope.builder()
118118
.forTesting()
119119
.withSpy(PEmailer.class) // has a primary
120120
.build()) {
@@ -130,7 +130,7 @@ void withMockitoSpy_whenPrimary_expect_spyUsed() {
130130
@Test
131131
void withMockitoSpy_whenOnlySecondary_expect_spyUsed() {
132132

133-
try (BeanScope context = BeanScope.newBuilder()
133+
try (BeanScope context = BeanScope.builder()
134134
.forTesting()
135135
.withSpy(Widget.class) // only secondary
136136
.build()) {
@@ -154,7 +154,7 @@ void withMockitoSpy_whenOnlySecondary_expect_spyUsed() {
154154
@Test
155155
void withNamed_when_qualifierNameDoesNotExist_but_onlyOneCandidate() {
156156

157-
try (BeanScope context = BeanScope.newBuilder()
157+
try (BeanScope context = BeanScope.builder()
158158
.build()) {
159159

160160
WidgetUser widgetUser = context.get(WidgetUser.class);
@@ -172,7 +172,7 @@ void withNamed_when_qualifierNameDoesNotExist_but_onlyOneCandidate() {
172172
@Test
173173
void withMockitoSpy_whenSecondary_expect_spyUsed() {
174174

175-
try (BeanScope context = BeanScope.newBuilder()
175+
try (BeanScope context = BeanScope.builder()
176176
.forTesting()
177177
.withSpy(Something.class) // has a secondary and a normal
178178
.build()) {
@@ -196,7 +196,7 @@ void withMockitoMock_expect_mockUsed() {
196196

197197
AtomicReference<Grinder> mock = new AtomicReference<>();
198198

199-
try (BeanScope context = BeanScope.newBuilder()
199+
try (BeanScope context = BeanScope.builder()
200200
.forTesting()
201201
.withMock(Pump.class)
202202
.withMock(Grinder.class, grinder -> {

0 commit comments

Comments
 (0)