Properly close context hierarchy in tests
Prior to this commit, some tests were creating a parent/child relationship but were only closing the child context. This could be an issue with the autoconfig module as a lot of auto-config kicks in by default. This commit adds a new test utility designed to properly handle those situations. Updated tests that were creating a context hierarchy to benefit from that. Fixes gh-1034
This commit is contained in:
committed by
Dave Syer
parent
f83395b40c
commit
b646231327
@@ -20,7 +20,7 @@ import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.boot.test.ApplicationContextTestUtils;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
/**
|
||||
@@ -34,13 +34,7 @@ public class SpringApplicationHierarchyTests {
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
if (this.context != null) {
|
||||
ApplicationContext parentContext = this.context.getParent();
|
||||
if (parentContext instanceof ConfigurableApplicationContext) {
|
||||
((ConfigurableApplicationContext) parentContext).close();
|
||||
}
|
||||
this.context.close();
|
||||
}
|
||||
ApplicationContextTestUtils.closeAll(this.context);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.ApplicationContextTestUtils;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -44,9 +45,7 @@ public class ShutdownParentEndpointTests {
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
ApplicationContextTestUtils.closeAll(this.context);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user