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.
14
14
* limitations under the License.
15
15
*/
16
16
17
- package org .springframework .beans .factory ;
18
-
19
- import static org .junit .Assert .*;
20
-
21
- import java .util .Arrays ;
17
+ package org .springframework .beans .factory .support ;
22
18
23
19
import org .junit .Test ;
20
+
24
21
import org .springframework .beans .BeansException ;
25
- import org .springframework .beans .factory .support . DefaultSingletonBeanRegistry ;
22
+ import org .springframework .beans .factory .ObjectFactory ;
26
23
import org .springframework .tests .sample .beans .DerivedTestBean ;
27
24
import org .springframework .tests .sample .beans .TestBean ;
28
25
26
+ import static org .junit .Assert .*;
27
+
29
28
/**
30
29
* @author Juergen Hoeller
31
30
* @author Chris Beams
32
31
* @since 04.07.2006
33
32
*/
34
- public final class SharedBeanRegistryTests {
33
+ public class DefaultSingletonBeanRegistryTests {
35
34
36
35
@ Test
37
36
public void testSingletons () {
@@ -52,9 +51,10 @@ public Object getObject() throws BeansException {
52
51
assertSame (tb , beanRegistry .getSingleton ("tb" ));
53
52
assertSame (tb2 , beanRegistry .getSingleton ("tb2" ));
54
53
assertEquals (2 , beanRegistry .getSingletonCount ());
55
- assertEquals (2 , beanRegistry .getSingletonNames ().length );
56
- assertTrue (Arrays .asList (beanRegistry .getSingletonNames ()).contains ("tb" ));
57
- assertTrue (Arrays .asList (beanRegistry .getSingletonNames ()).contains ("tb2" ));
54
+ String [] names = beanRegistry .getSingletonNames ();
55
+ assertEquals (2 , names .length );
56
+ assertEquals ("tb" , names [0 ]);
57
+ assertEquals ("tb2" , names [1 ]);
58
58
59
59
beanRegistry .destroySingletons ();
60
60
assertEquals (0 , beanRegistry .getSingletonCount ());
@@ -72,8 +72,9 @@ public void testDisposableBean() {
72
72
73
73
assertSame (tb , beanRegistry .getSingleton ("tb" ));
74
74
assertEquals (1 , beanRegistry .getSingletonCount ());
75
- assertEquals (1 , beanRegistry .getSingletonNames ().length );
76
- assertTrue (Arrays .asList (beanRegistry .getSingletonNames ()).contains ("tb" ));
75
+ String [] names = beanRegistry .getSingletonNames ();
76
+ assertEquals (1 , names .length );
77
+ assertEquals ("tb" , names [0 ]);
77
78
assertFalse (tb .wasDestroyed ());
78
79
79
80
beanRegistry .destroySingletons ();
@@ -82,4 +83,22 @@ public void testDisposableBean() {
82
83
assertTrue (tb .wasDestroyed ());
83
84
}
84
85
86
+ @ Test
87
+ public void testDependentRegistration () {
88
+ DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry ();
89
+
90
+ beanRegistry .registerDependentBean ("a" , "b" );
91
+ beanRegistry .registerDependentBean ("b" , "c" );
92
+ beanRegistry .registerDependentBean ("c" , "b" );
93
+ assertTrue (beanRegistry .isDependent ("a" , "b" ));
94
+ assertTrue (beanRegistry .isDependent ("b" , "c" ));
95
+ assertTrue (beanRegistry .isDependent ("c" , "b" ));
96
+ assertTrue (beanRegistry .isDependent ("a" , "c" ));
97
+ assertFalse (beanRegistry .isDependent ("c" , "a" ));
98
+ assertFalse (beanRegistry .isDependent ("b" , "a" ));
99
+ assertFalse (beanRegistry .isDependent ("a" , "a" ));
100
+ assertTrue (beanRegistry .isDependent ("b" , "b" ));
101
+ assertTrue (beanRegistry .isDependent ("c" , "c" ));
102
+ }
103
+
85
104
}
0 commit comments