1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
import org .springframework .beans .factory .support .RootBeanDefinition ;
24
24
import org .springframework .context .ApplicationContext ;
25
25
import org .springframework .context .ApplicationContextAware ;
26
+ import org .springframework .core .metrics .jfr .FlightRecorderApplicationStartup ;
26
27
import org .springframework .util .ObjectUtils ;
27
28
28
29
import static org .assertj .core .api .Assertions .assertThat ;
36
37
public class GenericApplicationContextTests {
37
38
38
39
@ Test
39
- public void getBeanForClass () {
40
+ void getBeanForClass () {
40
41
GenericApplicationContext ac = new GenericApplicationContext ();
41
42
ac .registerBeanDefinition ("testBean" , new RootBeanDefinition (String .class ));
42
43
ac .refresh ();
@@ -50,7 +51,7 @@ public void getBeanForClass() {
50
51
}
51
52
52
53
@ Test
53
- public void withSingletonSupplier () {
54
+ void withSingletonSupplier () {
54
55
GenericApplicationContext ac = new GenericApplicationContext ();
55
56
ac .registerBeanDefinition ("testBean" , new RootBeanDefinition (String .class , ac ::toString ));
56
57
ac .refresh ();
@@ -62,7 +63,7 @@ public void withSingletonSupplier() {
62
63
}
63
64
64
65
@ Test
65
- public void withScopedSupplier () {
66
+ void withScopedSupplier () {
66
67
GenericApplicationContext ac = new GenericApplicationContext ();
67
68
ac .registerBeanDefinition ("testBean" ,
68
69
new RootBeanDefinition (String .class , BeanDefinition .SCOPE_PROTOTYPE , ac ::toString ));
@@ -75,7 +76,7 @@ public void withScopedSupplier() {
75
76
}
76
77
77
78
@ Test
78
- public void accessAfterClosing () {
79
+ void accessAfterClosing () {
79
80
GenericApplicationContext ac = new GenericApplicationContext ();
80
81
ac .registerBeanDefinition ("testBean" , new RootBeanDefinition (String .class ));
81
82
ac .refresh ();
@@ -95,7 +96,7 @@ public void accessAfterClosing() {
95
96
}
96
97
97
98
@ Test
98
- public void individualBeans () {
99
+ void individualBeans () {
99
100
GenericApplicationContext context = new GenericApplicationContext ();
100
101
context .registerBean (BeanA .class );
101
102
context .registerBean (BeanB .class );
@@ -108,7 +109,7 @@ public void individualBeans() {
108
109
}
109
110
110
111
@ Test
111
- public void individualNamedBeans () {
112
+ void individualNamedBeans () {
112
113
GenericApplicationContext context = new GenericApplicationContext ();
113
114
context .registerBean ("a" , BeanA .class );
114
115
context .registerBean ("b" , BeanB .class );
@@ -121,7 +122,7 @@ public void individualNamedBeans() {
121
122
}
122
123
123
124
@ Test
124
- public void individualBeanWithSupplier () {
125
+ void individualBeanWithSupplier () {
125
126
GenericApplicationContext context = new GenericApplicationContext ();
126
127
context .registerBean (BeanA .class ,
127
128
() -> new BeanA (context .getBean (BeanB .class ), context .getBean (BeanC .class )));
@@ -139,7 +140,7 @@ public void individualBeanWithSupplier() {
139
140
}
140
141
141
142
@ Test
142
- public void individualBeanWithSupplierAndCustomizer () {
143
+ void individualBeanWithSupplierAndCustomizer () {
143
144
GenericApplicationContext context = new GenericApplicationContext ();
144
145
context .registerBean (BeanA .class ,
145
146
() -> new BeanA (context .getBean (BeanB .class ), context .getBean (BeanC .class )),
@@ -155,7 +156,7 @@ public void individualBeanWithSupplierAndCustomizer() {
155
156
}
156
157
157
158
@ Test
158
- public void individualNamedBeanWithSupplier () {
159
+ void individualNamedBeanWithSupplier () {
159
160
GenericApplicationContext context = new GenericApplicationContext ();
160
161
context .registerBean ("a" , BeanA .class ,
161
162
() -> new BeanA (context .getBean (BeanB .class ), context .getBean (BeanC .class )));
@@ -170,7 +171,7 @@ public void individualNamedBeanWithSupplier() {
170
171
}
171
172
172
173
@ Test
173
- public void individualNamedBeanWithSupplierAndCustomizer () {
174
+ void individualNamedBeanWithSupplierAndCustomizer () {
174
175
GenericApplicationContext context = new GenericApplicationContext ();
175
176
context .registerBean ("a" , BeanA .class ,
176
177
() -> new BeanA (context .getBean (BeanB .class ), context .getBean (BeanC .class )),
@@ -186,7 +187,7 @@ public void individualNamedBeanWithSupplierAndCustomizer() {
186
187
}
187
188
188
189
@ Test
189
- public void individualBeanWithNullReturningSupplier () {
190
+ void individualBeanWithNullReturningSupplier () {
190
191
GenericApplicationContext context = new GenericApplicationContext ();
191
192
context .registerBean ("a" , BeanA .class , () -> null );
192
193
context .registerBean ("b" , BeanB .class , BeanB ::new );
@@ -201,6 +202,14 @@ public void individualBeanWithNullReturningSupplier() {
201
202
assertThat (context .getBeansOfType (BeanC .class ).values ().iterator ().next ()).isSameAs (context .getBean (BeanC .class ));
202
203
}
203
204
205
+ @ Test
206
+ void configureApplicationStartupOnBeanFactory () {
207
+ FlightRecorderApplicationStartup applicationStartup = new FlightRecorderApplicationStartup ();
208
+ GenericApplicationContext context = new GenericApplicationContext ();
209
+ context .setApplicationStartup (applicationStartup );
210
+ assertThat (context .getBeanFactory ().getApplicationStartup ()).isEqualTo (applicationStartup );
211
+ }
212
+
204
213
205
214
static class BeanA {
206
215
0 commit comments