11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2013 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .context .annotation ;
1818
19- import static org .hamcrest .CoreMatchers .is ;
20- import static org .junit .Assert .assertThat ;
21-
2219import java .io .Closeable ;
2320import java .io .IOException ;
2421
2522import org .junit .Test ;
23+
2624import org .springframework .context .ConfigurableApplicationContext ;
2725import org .springframework .context .support .GenericXmlApplicationContext ;
2826
27+ import static org .hamcrest .CoreMatchers .*;
28+ import static org .junit .Assert .*;
29+
30+ /**
31+ * @author Chris Beams
32+ * @author Juergen Hoeller
33+ */
2934public class DestroyMethodInferenceTests {
3035
3136 @ Test
@@ -39,6 +44,7 @@ public void beanMethods() {
3944 WithInheritedCloseMethod c4 = ctx .getBean ("c4" , WithInheritedCloseMethod .class );
4045 WithInheritedCloseMethod c5 = ctx .getBean ("c5" , WithInheritedCloseMethod .class );
4146 WithNoCloseMethod c6 = ctx .getBean ("c6" , WithNoCloseMethod .class );
47+ WithLocalShutdownMethod c7 = ctx .getBean ("c7" , WithLocalShutdownMethod .class );
4248
4349 assertThat (c0 .closed , is (false ));
4450 assertThat (c1 .closed , is (false ));
@@ -47,6 +53,7 @@ public void beanMethods() {
4753 assertThat (c4 .closed , is (false ));
4854 assertThat (c5 .closed , is (false ));
4955 assertThat (c6 .closed , is (false ));
56+ assertThat (c7 .closed , is (false ));
5057 ctx .close ();
5158 assertThat ("c0" , c0 .closed , is (true ));
5259 assertThat ("c1" , c1 .closed , is (true ));
@@ -55,6 +62,7 @@ public void beanMethods() {
5562 assertThat ("c4" , c4 .closed , is (true ));
5663 assertThat ("c5" , c5 .closed , is (true ));
5764 assertThat ("c6" , c6 .closed , is (false ));
65+ assertThat ("c7" , c7 .closed , is (true ));
5866 }
5967
6068 @ Test
@@ -121,6 +129,11 @@ public void other() {
121129 public WithNoCloseMethod c6 () {
122130 return new WithNoCloseMethod ();
123131 }
132+
133+ @ Bean
134+ public WithLocalShutdownMethod c7 () {
135+ return new WithLocalShutdownMethod ();
136+ }
124137 }
125138
126139
@@ -149,4 +162,12 @@ public void close() throws IOException {
149162 static class WithNoCloseMethod {
150163 boolean closed = false ;
151164 }
165+
166+ static class WithLocalShutdownMethod {
167+ boolean closed = false ;
168+ public void shutdown () {
169+ closed = true ;
170+ }
171+ }
172+
152173}
0 commit comments