Properly close application context in tests
This commit is contained in:
@@ -67,10 +67,9 @@ public class CrshAutoConfigurationTests {
|
||||
private AnnotationConfigWebApplicationContext context;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
this.context = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.TestUtils;
|
||||
@@ -53,6 +54,13 @@ public class EndpointAutoConfigurationTests {
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpoints() throws Exception {
|
||||
assertNotNull(this.context.getBean(BeansEndpoint.class));
|
||||
|
||||
@@ -59,11 +59,9 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
try {
|
||||
if (this.applicationContext != null) {
|
||||
this.applicationContext.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.TestUtils;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializer;
|
||||
@@ -52,6 +53,13 @@ public class ManagementSecurityAutoConfigurationTests {
|
||||
|
||||
private AnnotationConfigWebApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
/**
|
||||
@@ -34,6 +35,10 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -55,7 +60,8 @@ public class SpringApplicationHierarchyTests {
|
||||
public static class Child {
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration(exclude = { ServerPropertiesAutoConfiguration.class })
|
||||
@EnableAutoConfiguration(exclude = { ServerPropertiesAutoConfiguration.class,
|
||||
JolokiaAutoConfiguration.class })
|
||||
public static class Parent {
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.TestUtils;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
@@ -68,6 +68,13 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void producesMediaType() {
|
||||
assertThat(getEndpointBean().getProduces(), equalTo(this.produces));
|
||||
|
||||
Reference in New Issue
Block a user