1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 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 static org .hamcrest .CoreMatchers .is ;
20
- import static org .junit .Assert .assertThat ;
21
-
22
19
import java .io .Closeable ;
23
20
import java .io .IOException ;
24
21
25
22
import org .junit .Test ;
23
+
26
24
import org .springframework .context .ConfigurableApplicationContext ;
27
25
import org .springframework .context .support .GenericXmlApplicationContext ;
28
26
27
+ import static org .hamcrest .CoreMatchers .*;
28
+ import static org .junit .Assert .*;
29
+
30
+ /**
31
+ * @author Chris Beams
32
+ * @author Juergen Hoeller
33
+ */
29
34
public class DestroyMethodInferenceTests {
30
35
31
36
@ Test
@@ -39,6 +44,7 @@ public void beanMethods() {
39
44
WithInheritedCloseMethod c4 = ctx .getBean ("c4" , WithInheritedCloseMethod .class );
40
45
WithInheritedCloseMethod c5 = ctx .getBean ("c5" , WithInheritedCloseMethod .class );
41
46
WithNoCloseMethod c6 = ctx .getBean ("c6" , WithNoCloseMethod .class );
47
+ WithLocalShutdownMethod c7 = ctx .getBean ("c7" , WithLocalShutdownMethod .class );
42
48
43
49
assertThat (c0 .closed , is (false ));
44
50
assertThat (c1 .closed , is (false ));
@@ -47,6 +53,7 @@ public void beanMethods() {
47
53
assertThat (c4 .closed , is (false ));
48
54
assertThat (c5 .closed , is (false ));
49
55
assertThat (c6 .closed , is (false ));
56
+ assertThat (c7 .closed , is (false ));
50
57
ctx .close ();
51
58
assertThat ("c0" , c0 .closed , is (true ));
52
59
assertThat ("c1" , c1 .closed , is (true ));
@@ -55,6 +62,7 @@ public void beanMethods() {
55
62
assertThat ("c4" , c4 .closed , is (true ));
56
63
assertThat ("c5" , c5 .closed , is (true ));
57
64
assertThat ("c6" , c6 .closed , is (false ));
65
+ assertThat ("c7" , c7 .closed , is (true ));
58
66
}
59
67
60
68
@ Test
@@ -121,6 +129,11 @@ public void other() {
121
129
public WithNoCloseMethod c6 () {
122
130
return new WithNoCloseMethod ();
123
131
}
132
+
133
+ @ Bean
134
+ public WithLocalShutdownMethod c7 () {
135
+ return new WithLocalShutdownMethod ();
136
+ }
124
137
}
125
138
126
139
@@ -149,4 +162,12 @@ public void close() throws IOException {
149
162
static class WithNoCloseMethod {
150
163
boolean closed = false ;
151
164
}
165
+
166
+ static class WithLocalShutdownMethod {
167
+ boolean closed = false ;
168
+ public void shutdown () {
169
+ closed = true ;
170
+ }
171
+ }
172
+
152
173
}
0 commit comments