@@ -49,10 +49,19 @@ public class ContextHierarchyDirtiesContextTests {
49
49
50
50
private static ApplicationContext context ;
51
51
52
+ private static String foo ;
53
+
54
+ private static String bar ;
55
+
56
+ private static String baz ;
57
+
52
58
53
59
@ After
54
60
public void cleanUp () {
55
61
ContextHierarchyDirtiesContextTests .context = null ;
62
+ ContextHierarchyDirtiesContextTests .foo = null ;
63
+ ContextHierarchyDirtiesContextTests .bar = null ;
64
+ ContextHierarchyDirtiesContextTests .baz = null ;
56
65
}
57
66
58
67
@ Test
@@ -85,17 +94,17 @@ private void runTestAndVerifyHierarchies(Class<? extends FooTestCase> testClass,
85
94
assertThat (ContextHierarchyDirtiesContextTests .context , notNullValue ());
86
95
87
96
ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext ) ContextHierarchyDirtiesContextTests .context ;
88
- assertEquals ("baz" , bazContext . getBean ( "bean" , String . class ) );
97
+ assertEquals ("baz" , ContextHierarchyDirtiesContextTests . baz );
89
98
assertThat ("bazContext#isActive()" , bazContext .isActive (), is (isBazContextActive ));
90
99
91
100
ConfigurableApplicationContext barContext = (ConfigurableApplicationContext ) bazContext .getParent ();
92
101
assertThat (barContext , notNullValue ());
93
- assertEquals ("bar" , barContext . getBean ( "bean" , String . class ) );
102
+ assertEquals ("bar" , ContextHierarchyDirtiesContextTests . bar );
94
103
assertThat ("barContext#isActive()" , barContext .isActive (), is (isBarContextActive ));
95
104
96
105
ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext ) barContext .getParent ();
97
106
assertThat (fooContext , notNullValue ());
98
- assertEquals ("foo" , fooContext . getBean ( "bean" , String . class ) );
107
+ assertEquals ("foo" , ContextHierarchyDirtiesContextTests . foo );
99
108
assertThat ("fooContext#isActive()" , fooContext .isActive (), is (isFooContextActive ));
100
109
}
101
110
@@ -115,9 +124,11 @@ public String bean() {
115
124
}
116
125
}
117
126
118
-
119
127
public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
120
128
ContextHierarchyDirtiesContextTests .context = applicationContext ;
129
+ ContextHierarchyDirtiesContextTests .baz = applicationContext .getBean ("bean" , String .class );
130
+ ContextHierarchyDirtiesContextTests .bar = applicationContext .getParent ().getBean ("bean" , String .class );
131
+ ContextHierarchyDirtiesContextTests .foo = applicationContext .getParent ().getParent ().getBean ("bean" , String .class );
121
132
}
122
133
}
123
134
0 commit comments