From e769f20477c413a79fec551f42715415308516b5 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Wed, 13 Apr 2016 11:26:03 +0900 Subject: [PATCH] Close the context in TypeExcludeFilterTests Closes gh-5672 --- .../boot/context/TypeExcludeFilterTests.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/TypeExcludeFilterTests.java b/spring-boot/src/test/java/org/springframework/boot/context/TypeExcludeFilterTests.java index abb82ecbbb2..5ddfbc7a937 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/TypeExcludeFilterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/TypeExcludeFilterTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.context; +import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -42,19 +43,27 @@ public class TypeExcludeFilterTests { @Rule public ExpectedException thrown = ExpectedException.none(); + private AnnotationConfigApplicationContext context; + + @After + public void cleanUp() { + if (this.context != null) { + this.context.close(); + } + } + @Test public void loadsTypeExcludeFilters() throws Exception { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.getBeanFactory().registerSingleton("filter1", + this.context = new AnnotationConfigApplicationContext(); + this.context.getBeanFactory().registerSingleton("filter1", new WithoutMatchOverrideFilter()); - context.getBeanFactory().registerSingleton("filter2", + this.context.getBeanFactory().registerSingleton("filter2", new SampleTypeExcludeFilter()); - context.register(Config.class); - context.refresh(); - assertThat(context.getBean(ExampleComponent.class)).isNotNull(); + this.context.register(Config.class); + this.context.refresh(); + assertThat(this.context.getBean(ExampleComponent.class)).isNotNull(); this.thrown.expect(NoSuchBeanDefinitionException.class); - context.getBean(ExampleFilteredComponent.class); - context.close(); + this.context.getBean(ExampleFilteredComponent.class); } @Configuration