Add null-safe static utility method used to close a given Spring ApplicationContext.

This commit is contained in:
John Blum
2021-09-08 12:48:50 -07:00
parent 3aefdaa81b
commit fced306b12
2 changed files with 10 additions and 1 deletions

View File

@@ -54,6 +54,7 @@ import org.apache.geode.internal.net.SocketCreatorFactory;
import org.apache.shiro.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
@@ -248,6 +249,14 @@ public abstract class IntegrationTestsSupport {
.forEach(InternalDataSerializer::unregister);
}
public static void closeApplicationContext(@Nullable ApplicationContext applicationContext) {
Optional.ofNullable(applicationContext)
.filter(ConfigurableApplicationContext.class::isInstance)
.map(ConfigurableApplicationContext.class::cast)
.ifPresent(ConfigurableApplicationContext::close);
}
public static void closeGemFireCacheWaitOnCacheClosedEvent() {
closeGemFireCacheWaitOnCacheClosedEvent(DEFAULT_WAIT_DURATION);
}

View File

@@ -55,7 +55,7 @@ public abstract class SpringApplicationContextIntegrationTestsSupport extends In
@After
public void closeApplicationContext() {
getOptionalApplicationContext().ifPresent(ConfigurableApplicationContext::close);
closeApplicationContext(this.applicationContext);
}
protected ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {