Commit e769f204 authored by Johnny Lim's avatar Johnny Lim Committed by Phillip Webb

Close the context in TypeExcludeFilterTests

Closes gh-5672
parent bf1fcfc8
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.boot.context; package org.springframework.boot.context;
import org.junit.After;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
...@@ -42,19 +43,27 @@ public class TypeExcludeFilterTests { ...@@ -42,19 +43,27 @@ public class TypeExcludeFilterTests {
@Rule @Rule
public ExpectedException thrown = ExpectedException.none(); public ExpectedException thrown = ExpectedException.none();
private AnnotationConfigApplicationContext context;
@After
public void cleanUp() {
if (this.context != null) {
this.context.close();
}
}
@Test @Test
public void loadsTypeExcludeFilters() throws Exception { public void loadsTypeExcludeFilters() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
context.getBeanFactory().registerSingleton("filter1", this.context.getBeanFactory().registerSingleton("filter1",
new WithoutMatchOverrideFilter()); new WithoutMatchOverrideFilter());
context.getBeanFactory().registerSingleton("filter2", this.context.getBeanFactory().registerSingleton("filter2",
new SampleTypeExcludeFilter()); new SampleTypeExcludeFilter());
context.register(Config.class); this.context.register(Config.class);
context.refresh(); this.context.refresh();
assertThat(context.getBean(ExampleComponent.class)).isNotNull(); assertThat(this.context.getBean(ExampleComponent.class)).isNotNull();
this.thrown.expect(NoSuchBeanDefinitionException.class); this.thrown.expect(NoSuchBeanDefinitionException.class);
context.getBean(ExampleFilteredComponent.class); this.context.getBean(ExampleFilteredComponent.class);
context.close();
} }
@Configuration @Configuration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment