Commit 845aeecb authored by Christian Dupuis's avatar Christian Dupuis

Properly close application context in tests

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