16
16
17
17
package org .springframework .boot .context ;
18
18
19
+ import org .junit .After ;
19
20
import org .junit .Rule ;
20
21
import org .junit .Test ;
21
22
import org .junit .rules .ExpectedException ;
@@ -42,19 +43,27 @@ public class TypeExcludeFilterTests {
42
43
@ Rule
43
44
public ExpectedException thrown = ExpectedException .none ();
44
45
46
+ private AnnotationConfigApplicationContext context ;
47
+
48
+ @ After
49
+ public void cleanUp () {
50
+ if (this .context != null ) {
51
+ this .context .close ();
52
+ }
53
+ }
54
+
45
55
@ Test
46
56
public void loadsTypeExcludeFilters () throws Exception {
47
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
48
- context .getBeanFactory ().registerSingleton ("filter1" ,
57
+ this . context = new AnnotationConfigApplicationContext ();
58
+ this . context .getBeanFactory ().registerSingleton ("filter1" ,
49
59
new WithoutMatchOverrideFilter ());
50
- context .getBeanFactory ().registerSingleton ("filter2" ,
60
+ this . context .getBeanFactory ().registerSingleton ("filter2" ,
51
61
new SampleTypeExcludeFilter ());
52
- context .register (Config .class );
53
- context .refresh ();
54
- assertThat (context .getBean (ExampleComponent .class )).isNotNull ();
62
+ this . context .register (Config .class );
63
+ this . context .refresh ();
64
+ assertThat (this . context .getBean (ExampleComponent .class )).isNotNull ();
55
65
this .thrown .expect (NoSuchBeanDefinitionException .class );
56
- context .getBean (ExampleFilteredComponent .class );
57
- context .close ();
66
+ this .context .getBean (ExampleFilteredComponent .class );
58
67
}
59
68
60
69
@ Configuration
0 commit comments