@@ -139,22 +139,24 @@ public void testDoubleTargetSourcesAreRejected() {
139
139
private void testDoubleTargetSourceIsRejected (String name ) {
140
140
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
141
141
new XmlBeanDefinitionReader (bf ).loadBeanDefinitions (new ClassPathResource (DBL_TARGETSOURCE_CONTEXT , CLASS ));
142
+
142
143
assertThatExceptionOfType (BeanCreationException .class ).as ("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property" )
143
- .isThrownBy (() -> bf .getBean (name ))
144
- .havingCause ()
145
- .isInstanceOf (AopConfigException .class )
146
- .withMessageContaining ("TargetSource" );
144
+ .isThrownBy (() -> bf .getBean (name ))
145
+ .havingCause ()
146
+ .isInstanceOf (AopConfigException .class )
147
+ .withMessageContaining ("TargetSource" );
147
148
}
148
149
149
150
@ Test
150
151
public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected () {
151
152
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
152
153
new XmlBeanDefinitionReader (bf ).loadBeanDefinitions (new ClassPathResource (NOTLAST_TARGETSOURCE_CONTEXT , CLASS ));
154
+
153
155
assertThatExceptionOfType (BeanCreationException .class ).as ("TargetSource or non-advised object must be last in interceptorNames" )
154
- .isThrownBy (() -> bf .getBean ("targetSourceNotLast" ))
155
- .havingCause ()
156
- .isInstanceOf (AopConfigException .class )
157
- .withMessageContaining ("interceptorNames" );
156
+ .isThrownBy (() -> bf .getBean ("targetSourceNotLast" ))
157
+ .havingCause ()
158
+ .isInstanceOf (AopConfigException .class )
159
+ .withMessageContaining ("interceptorNames" );
158
160
}
159
161
160
162
@ Test
@@ -171,7 +173,7 @@ public void testGetObjectTypeWithDirectTarget() {
171
173
assertThat (cba .getCalls ()).isEqualTo (1 );
172
174
173
175
ProxyFactoryBean pfb = (ProxyFactoryBean ) bf .getBean ("&directTarget" );
174
- assertThat (TestBean . class . isAssignableFrom ( pfb .getObjectType ())). as ( "Has correct object type" ). isTrue ( );
176
+ assertThat (pfb .getObjectType ()). isAssignableTo ( TestBean . class );
175
177
}
176
178
177
179
@ Test
@@ -181,7 +183,7 @@ public void testGetObjectTypeWithTargetViaTargetSource() {
181
183
ITestBean tb = (ITestBean ) bf .getBean ("viaTargetSource" );
182
184
assertThat (tb .getName ()).isEqualTo ("Adam" );
183
185
ProxyFactoryBean pfb = (ProxyFactoryBean ) bf .getBean ("&viaTargetSource" );
184
- assertThat (TestBean . class . isAssignableFrom ( pfb .getObjectType ())). as ( "Has correct object type" ). isTrue ( );
186
+ assertThat (pfb .getObjectType ()). isAssignableTo ( TestBean . class );
185
187
}
186
188
187
189
@ Test
@@ -190,11 +192,15 @@ public void testGetObjectTypeWithNoTargetOrTargetSource() {
190
192
new XmlBeanDefinitionReader (bf ).loadBeanDefinitions (new ClassPathResource (TARGETSOURCE_CONTEXT , CLASS ));
191
193
192
194
ITestBean tb = (ITestBean ) bf .getBean ("noTarget" );
193
- assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (() ->
194
- tb .getName ())
195
- .withMessage ("getName" );
195
+ assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (tb ::getName ).withMessage ("getName" );
196
196
FactoryBean <?> pfb = (ProxyFactoryBean ) bf .getBean ("&noTarget" );
197
- assertThat (ITestBean .class .isAssignableFrom (pfb .getObjectType ())).as ("Has correct object type" ).isTrue ();
197
+ assertThat (pfb .getObjectType ()).isAssignableTo (ITestBean .class );
198
+ }
199
+
200
+ @ Test
201
+ public void testGetObjectTypeOnUninitializedFactoryBean () {
202
+ ProxyFactoryBean pfb = new ProxyFactoryBean ();
203
+ assertThat (pfb .getObjectType ()).isNull ();
198
204
}
199
205
200
206
/**
@@ -227,12 +233,12 @@ public void testSingletonInstancesAreEqual() {
227
233
228
234
@ Test
229
235
public void testPrototypeInstancesAreNotEqual () {
230
- assertThat (ITestBean . class . isAssignableFrom ( factory .getType ("prototype" ))). as ( "Has correct object type" ). isTrue ( );
236
+ assertThat (factory .getType ("prototype" )). isAssignableTo ( ITestBean . class );
231
237
ITestBean test2 = (ITestBean ) factory .getBean ("prototype" );
232
238
ITestBean test2_1 = (ITestBean ) factory .getBean ("prototype" );
233
239
assertThat (test2 ).as ("Prototype instances !=" ).isNotSameAs (test2_1 );
234
240
assertThat (test2 ).as ("Prototype instances equal" ).isEqualTo (test2_1 );
235
- assertThat (ITestBean . class . isAssignableFrom ( factory .getType ("prototype" ))). as ( "Has correct object type" ). isTrue ( );
241
+ assertThat (factory .getType ("prototype" )). isAssignableTo ( ITestBean . class );
236
242
}
237
243
238
244
/**
@@ -291,13 +297,13 @@ public void testAutoInvoker() {
291
297
@ Test
292
298
public void testCanGetFactoryReferenceAndManipulate () {
293
299
ProxyFactoryBean config = (ProxyFactoryBean ) factory .getBean ("&test1" );
294
- assertThat (ITestBean . class . isAssignableFrom ( config .getObjectType ())). as ( "Has correct object type" ). isTrue ( );
295
- assertThat (ITestBean . class . isAssignableFrom ( factory .getType ("test1" ))). as ( "Has correct object type" ). isTrue ( );
300
+ assertThat (config .getObjectType ()). isAssignableTo ( ITestBean . class );
301
+ assertThat (factory .getType ("test1" )). isAssignableTo ( ITestBean . class );
296
302
// Trigger lazy initialization.
297
303
config .getObject ();
298
304
assertThat (config .getAdvisors ().length ).as ("Have one advisors" ).isEqualTo (1 );
299
- assertThat (ITestBean . class . isAssignableFrom ( config .getObjectType ())). as ( "Has correct object type" ). isTrue ( );
300
- assertThat (ITestBean . class . isAssignableFrom ( factory .getType ("test1" ))). as ( "Has correct object type" ). isTrue ( );
305
+ assertThat (config .getObjectType ()). isAssignableTo ( ITestBean . class );
306
+ assertThat (factory .getType ("test1" )). isAssignableTo ( ITestBean . class );
301
307
302
308
ITestBean tb = (ITestBean ) factory .getBean ("test1" );
303
309
// no exception
0 commit comments