Skip to content

Commit 57a665c

Browse files
committed
Merge pull request spring-projects#5672 from izeye/context-close
* context-close: Close the context in TypeExcludeFilterTests
2 parents bf1fcfc + e769f20 commit 57a665c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

spring-boot/src/test/java/org/springframework/boot/context/TypeExcludeFilterTests.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.context;
1818

19+
import org.junit.After;
1920
import org.junit.Rule;
2021
import org.junit.Test;
2122
import org.junit.rules.ExpectedException;
@@ -42,19 +43,27 @@ public class TypeExcludeFilterTests {
4243
@Rule
4344
public ExpectedException thrown = ExpectedException.none();
4445

46+
private AnnotationConfigApplicationContext context;
47+
48+
@After
49+
public void cleanUp() {
50+
if (this.context != null) {
51+
this.context.close();
52+
}
53+
}
54+
4555
@Test
4656
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",
4959
new WithoutMatchOverrideFilter());
50-
context.getBeanFactory().registerSingleton("filter2",
60+
this.context.getBeanFactory().registerSingleton("filter2",
5161
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();
5565
this.thrown.expect(NoSuchBeanDefinitionException.class);
56-
context.getBean(ExampleFilteredComponent.class);
57-
context.close();
66+
this.context.getBean(ExampleFilteredComponent.class);
5867
}
5968

6069
@Configuration

0 commit comments

Comments
 (0)