1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2015 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.
22
22
23
23
import org .junit .Test ;
24
24
25
- import org .springframework .beans .BeansException ;
26
25
import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
27
26
import org .springframework .beans .factory .config .BeanPostProcessor ;
28
27
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
39
38
* @author Juergen Hoeller
40
39
* @author Chris Beams
41
40
*/
42
- public final class FactoryBeanTests {
41
+ public class FactoryBeanTests {
43
42
44
43
private static final Class <?> CLASS = FactoryBeanTests .class ;
45
44
private static final Resource RETURNS_NULL_CONTEXT = qualifiedResource (CLASS , "returnsNull.xml" );
46
45
private static final Resource WITH_AUTOWIRING_CONTEXT = qualifiedResource (CLASS , "withAutowiring.xml" );
47
46
private static final Resource ABSTRACT_CONTEXT = qualifiedResource (CLASS , "abstract.xml" );
48
47
private static final Resource CIRCULAR_CONTEXT = qualifiedResource (CLASS , "circular.xml" );
49
48
49
+
50
50
@ Test
51
51
public void testFactoryBeanReturnsNull () throws Exception {
52
52
DefaultListableBeanFactory factory = new DefaultListableBeanFactory ();
@@ -63,10 +63,13 @@ public void testFactoryBeansWithAutowiring() throws Exception {
63
63
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor ) factory .getBean ("propertyPlaceholderConfigurer" );
64
64
ppc .postProcessBeanFactory (factory );
65
65
66
+ assertNull (factory .getType ("betaFactory" ));
67
+
66
68
Alpha alpha = (Alpha ) factory .getBean ("alpha" );
67
69
Beta beta = (Beta ) factory .getBean ("beta" );
68
70
Gamma gamma = (Gamma ) factory .getBean ("gamma" );
69
71
Gamma gamma2 = (Gamma ) factory .getBean ("gammaFactory" );
72
+
70
73
assertSame (beta , alpha .getBeta ());
71
74
assertSame (gamma , beta .getGamma ());
72
75
assertSame (gamma2 , beta .getGamma ());
@@ -194,6 +197,9 @@ public static class Gamma {
194
197
@ Component
195
198
public static class BetaFactoryBean implements FactoryBean <Object > {
196
199
200
+ public BetaFactoryBean (Alpha alpha ) {
201
+ }
202
+
197
203
private Beta beta ;
198
204
199
205
public void setBeta (Beta beta ) {
@@ -238,12 +244,12 @@ public PassThroughFactoryBean(Class<T> type) {
238
244
public void setInstanceName (String instanceName ) {
239
245
this .instanceName = instanceName ;
240
246
}
247
+
241
248
@ Override
242
- public void setBeanFactory (BeanFactory beanFactory ) throws BeansException {
249
+ public void setBeanFactory (BeanFactory beanFactory ) {
243
250
this .beanFactory = beanFactory ;
244
251
}
245
252
246
-
247
253
@ Override
248
254
public T getObject () {
249
255
if (instance == null ) {
0 commit comments