1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 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.
16
16
17
17
package org .springframework .context .annotation ;
18
18
19
- import junit .framework . TestCase ;
19
+ import org . junit .Test ;
20
20
21
21
import org .springframework .aop .scope .ScopedObject ;
22
22
import org .springframework .aop .support .AopUtils ;
25
25
import org .springframework .beans .factory .support .RootBeanDefinition ;
26
26
import org .springframework .context .annotation4 .DependencyBean ;
27
27
import org .springframework .context .annotation4 .FactoryMethodComponent ;
28
+ import org .springframework .context .support .AbstractApplicationContext ;
28
29
import org .springframework .context .support .GenericApplicationContext ;
29
30
import org .springframework .tests .context .SimpleMapScope ;
30
31
import org .springframework .tests .sample .beans .TestBean ;
31
32
import org .springframework .util .ClassUtils ;
32
33
34
+ import static org .junit .Assert .*;
35
+
33
36
/**
34
37
* @author Mark Pollack
35
38
* @author Juergen Hoeller
36
39
*/
37
- public class ClassPathFactoryBeanDefinitionScannerTests extends TestCase {
40
+ public class ClassPathFactoryBeanDefinitionScannerTests {
38
41
39
42
private static final String BASE_PACKAGE = FactoryMethodComponent .class .getPackage ().getName ();
40
43
41
44
45
+ @ Test
42
46
public void testSingletonScopedFactoryMethod () {
43
47
GenericApplicationContext context = new GenericApplicationContext ();
44
48
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner (context );
@@ -52,13 +56,13 @@ public void testSingletonScopedFactoryMethod() {
52
56
FactoryMethodComponent fmc = context .getBean ("factoryMethodComponent" , FactoryMethodComponent .class );
53
57
assertFalse (fmc .getClass ().getName ().contains (ClassUtils .CGLIB_CLASS_SEPARATOR ));
54
58
55
- TestBean tb = (TestBean )context .getBean ("publicInstance" ); //2
59
+ TestBean tb = (TestBean ) context .getBean ("publicInstance" ); //2
56
60
assertEquals ("publicInstance" , tb .getName ());
57
- TestBean tb2 = (TestBean )context .getBean ("publicInstance" ); //2
61
+ TestBean tb2 = (TestBean ) context .getBean ("publicInstance" ); //2
58
62
assertEquals ("publicInstance" , tb2 .getName ());
59
63
assertSame (tb2 , tb );
60
64
61
- tb = (TestBean )context .getBean ("protectedInstance" ); //3
65
+ tb = (TestBean ) context .getBean ("protectedInstance" ); //3
62
66
assertEquals ("protectedInstance" , tb .getName ());
63
67
assertSame (tb , context .getBean ("protectedInstance" ));
64
68
assertEquals ("0" , tb .getCountry ());
@@ -78,8 +82,9 @@ public void testSingletonScopedFactoryMethod() {
78
82
assertTrue (bean instanceof ScopedObject );
79
83
80
84
QualifiedClientBean clientBean = context .getBean ("clientBean" , QualifiedClientBean .class );
81
- assertSame (clientBean .testBean , context .getBean ("publicInstance" ));
82
- assertSame (clientBean .dependencyBean , context .getBean ("dependencyBean" ));
85
+ assertSame (context .getBean ("publicInstance" ), clientBean .testBean );
86
+ assertSame (context .getBean ("dependencyBean" ), clientBean .dependencyBean );
87
+ assertSame (context , clientBean .applicationContext );
83
88
}
84
89
85
90
@@ -90,6 +95,9 @@ public static class QualifiedClientBean {
90
95
91
96
@ Autowired
92
97
public DependencyBean dependencyBean ;
98
+
99
+ @ Autowired
100
+ AbstractApplicationContext applicationContext ;
93
101
}
94
102
95
103
}
0 commit comments