Consistently use mergedConfig as variable name for MergedContextConfiguration
This commit is contained in:
@@ -49,14 +49,14 @@ public interface CacheAwareContextLoaderDelegate {
|
||||
* therefore highly encouraged to override this method with a more meaningful
|
||||
* implementation. Note that the standard {@code CacheAwareContextLoaderDelegate}
|
||||
* implementation in Spring overrides this method appropriately.
|
||||
* @param mergedContextConfiguration the merged context configuration used
|
||||
* to load the application context; never {@code null}
|
||||
* @param mergedConfig the merged context configuration used to load the
|
||||
* application context; never {@code null}
|
||||
* @return {@code true} if the application context has been loaded
|
||||
* @since 5.2
|
||||
* @see #loadContext
|
||||
* @see #closeContext
|
||||
*/
|
||||
default boolean isContextLoaded(MergedContextConfiguration mergedContextConfiguration) {
|
||||
default boolean isContextLoaded(MergedContextConfiguration mergedConfig) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,15 +74,15 @@ public interface CacheAwareContextLoaderDelegate {
|
||||
* load failure if the exception is an instance of {@link ContextLoadException}.
|
||||
* <p>The cache statistics should be logged by invoking
|
||||
* {@link org.springframework.test.context.cache.ContextCache#logStatistics()}.
|
||||
* @param mergedContextConfiguration the merged context configuration to use
|
||||
* to load the application context; never {@code null}
|
||||
* @param mergedConfig the merged context configuration to use to load the
|
||||
* application context; never {@code null}
|
||||
* @return the application context (never {@code null})
|
||||
* @throws IllegalStateException if an error occurs while retrieving or loading
|
||||
* the application context
|
||||
* @see #isContextLoaded
|
||||
* @see #closeContext
|
||||
*/
|
||||
ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration);
|
||||
ApplicationContext loadContext(MergedContextConfiguration mergedConfig);
|
||||
|
||||
/**
|
||||
* Remove the {@linkplain ApplicationContext application context} for the
|
||||
@@ -96,14 +96,14 @@ public interface CacheAwareContextLoaderDelegate {
|
||||
* a singleton bean has been changed (potentially affecting future interaction
|
||||
* with the context) or if the context needs to be prematurely removed from
|
||||
* the cache.
|
||||
* @param mergedContextConfiguration the merged context configuration for the
|
||||
* application context to close; never {@code null}
|
||||
* @param mergedConfig the merged context configuration for the application
|
||||
* context to close; never {@code null}
|
||||
* @param hierarchyMode the hierarchy mode; may be {@code null} if the context
|
||||
* is not part of a hierarchy
|
||||
* @since 4.1
|
||||
* @see #isContextLoaded
|
||||
* @see #loadContext
|
||||
*/
|
||||
void closeContext(MergedContextConfiguration mergedContextConfiguration, @Nullable HierarchyMode hierarchyMode);
|
||||
void closeContext(MergedContextConfiguration mergedConfig, @Nullable HierarchyMode hierarchyMode);
|
||||
|
||||
}
|
||||
|
||||
@@ -99,31 +99,31 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isContextLoaded(MergedContextConfiguration mergedContextConfiguration) {
|
||||
mergedContextConfiguration = replaceIfNecessary(mergedContextConfiguration);
|
||||
public boolean isContextLoaded(MergedContextConfiguration mergedConfig) {
|
||||
mergedConfig = replaceIfNecessary(mergedConfig);
|
||||
synchronized (this.contextCache) {
|
||||
return this.contextCache.contains(mergedContextConfiguration);
|
||||
return this.contextCache.contains(mergedConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration) {
|
||||
mergedContextConfiguration = replaceIfNecessary(mergedContextConfiguration);
|
||||
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) {
|
||||
mergedConfig = replaceIfNecessary(mergedConfig);
|
||||
synchronized (this.contextCache) {
|
||||
ApplicationContext context = this.contextCache.get(mergedContextConfiguration);
|
||||
ApplicationContext context = this.contextCache.get(mergedConfig);
|
||||
if (context == null) {
|
||||
try {
|
||||
if (mergedContextConfiguration instanceof AotMergedContextConfiguration aotMergedConfig) {
|
||||
if (mergedConfig instanceof AotMergedContextConfiguration aotMergedConfig) {
|
||||
context = loadContextInAotMode(aotMergedConfig);
|
||||
}
|
||||
else {
|
||||
context = loadContextInternal(mergedContextConfiguration);
|
||||
context = loadContextInternal(mergedConfig);
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Storing ApplicationContext [%s] in cache under key %s".formatted(
|
||||
System.identityHashCode(context), mergedContextConfiguration));
|
||||
System.identityHashCode(context), mergedConfig));
|
||||
}
|
||||
this.contextCache.put(mergedContextConfiguration, context);
|
||||
this.contextCache.put(mergedConfig, context);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Throwable cause = ex;
|
||||
@@ -142,13 +142,13 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"Failed to load ApplicationContext for " + mergedContextConfiguration, cause);
|
||||
"Failed to load ApplicationContext for " + mergedConfig, cause);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Retrieved ApplicationContext [%s] from cache with key %s".formatted(
|
||||
System.identityHashCode(context), mergedContextConfiguration));
|
||||
System.identityHashCode(context), mergedConfig));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,10 +159,10 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeContext(MergedContextConfiguration mergedContextConfiguration, @Nullable HierarchyMode hierarchyMode) {
|
||||
mergedContextConfiguration = replaceIfNecessary(mergedContextConfiguration);
|
||||
public void closeContext(MergedContextConfiguration mergedConfig, @Nullable HierarchyMode hierarchyMode) {
|
||||
mergedConfig = replaceIfNecessary(mergedConfig);
|
||||
synchronized (this.contextCache) {
|
||||
this.contextCache.remove(mergedContextConfiguration, hierarchyMode);
|
||||
this.contextCache.remove(mergedConfig, hierarchyMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,19 +179,19 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
|
||||
* @throws Exception if an error occurs while loading the application context
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
|
||||
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedConfig)
|
||||
throws Exception {
|
||||
|
||||
ContextLoader contextLoader = getContextLoader(mergedContextConfiguration);
|
||||
ContextLoader contextLoader = getContextLoader(mergedConfig);
|
||||
if (contextLoader instanceof SmartContextLoader smartContextLoader) {
|
||||
return smartContextLoader.loadContext(mergedContextConfiguration);
|
||||
return smartContextLoader.loadContext(mergedConfig);
|
||||
}
|
||||
else {
|
||||
String[] locations = mergedContextConfiguration.getLocations();
|
||||
String[] locations = mergedConfig.getLocations();
|
||||
Assert.notNull(locations, () -> """
|
||||
Cannot load an ApplicationContext with a NULL 'locations' array. \
|
||||
Consider annotating test class [%s] with @ContextConfiguration or \
|
||||
@ContextHierarchy.""".formatted(mergedContextConfiguration.getTestClass().getName()));
|
||||
@ContextHierarchy.""".formatted(mergedConfig.getTestClass().getName()));
|
||||
return contextLoader.loadContext(locations);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,7 +51,7 @@ public class DefaultTestContext implements TestContext {
|
||||
|
||||
private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate;
|
||||
|
||||
private final MergedContextConfiguration mergedContextConfiguration;
|
||||
private final MergedContextConfiguration mergedConfig;
|
||||
|
||||
private final Class<?> testClass;
|
||||
|
||||
@@ -75,7 +75,7 @@ public class DefaultTestContext implements TestContext {
|
||||
* is {@code null}
|
||||
*/
|
||||
public DefaultTestContext(DefaultTestContext testContext) {
|
||||
this(testContext.testClass, testContext.mergedContextConfiguration,
|
||||
this(testContext.testClass, testContext.mergedConfig,
|
||||
testContext.cacheAwareContextLoaderDelegate);
|
||||
this.attributes.putAll(testContext.attributes);
|
||||
}
|
||||
@@ -83,19 +83,19 @@ public class DefaultTestContext implements TestContext {
|
||||
/**
|
||||
* Construct a new {@code DefaultTestContext} from the supplied arguments.
|
||||
* @param testClass the test class for this test context
|
||||
* @param mergedContextConfiguration the merged application context
|
||||
* @param mergedConfig the merged application context
|
||||
* configuration for this test context
|
||||
* @param cacheAwareContextLoaderDelegate the delegate to use for loading
|
||||
* and closing the application context for this test context
|
||||
*/
|
||||
public DefaultTestContext(Class<?> testClass, MergedContextConfiguration mergedContextConfiguration,
|
||||
public DefaultTestContext(Class<?> testClass, MergedContextConfiguration mergedConfig,
|
||||
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {
|
||||
|
||||
Assert.notNull(testClass, "Test Class must not be null");
|
||||
Assert.notNull(mergedContextConfiguration, "MergedContextConfiguration must not be null");
|
||||
Assert.notNull(mergedConfig, "MergedContextConfiguration must not be null");
|
||||
Assert.notNull(cacheAwareContextLoaderDelegate, "CacheAwareContextLoaderDelegate must not be null");
|
||||
this.testClass = testClass;
|
||||
this.mergedContextConfiguration = mergedContextConfiguration;
|
||||
this.mergedConfig = mergedConfig;
|
||||
this.cacheAwareContextLoaderDelegate = cacheAwareContextLoaderDelegate;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public class DefaultTestContext implements TestContext {
|
||||
*/
|
||||
@Override
|
||||
public boolean hasApplicationContext() {
|
||||
return this.cacheAwareContextLoaderDelegate.isContextLoaded(this.mergedContextConfiguration);
|
||||
return this.cacheAwareContextLoaderDelegate.isContextLoaded(this.mergedConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +124,7 @@ public class DefaultTestContext implements TestContext {
|
||||
*/
|
||||
@Override
|
||||
public ApplicationContext getApplicationContext() {
|
||||
ApplicationContext context = this.cacheAwareContextLoaderDelegate.loadContext(this.mergedContextConfiguration);
|
||||
ApplicationContext context = this.cacheAwareContextLoaderDelegate.loadContext(this.mergedConfig);
|
||||
if (context instanceof ConfigurableApplicationContext cac) {
|
||||
Assert.state(cac.isActive(), () -> """
|
||||
The ApplicationContext loaded for %s is not active. \
|
||||
@@ -133,7 +133,7 @@ public class DefaultTestContext implements TestContext {
|
||||
2) the context was closed during parallel test execution either \
|
||||
according to @DirtiesContext semantics or due to automatic eviction \
|
||||
from the ContextCache due to a maximum cache size policy."""
|
||||
.formatted(this.mergedContextConfiguration));
|
||||
.formatted(this.mergedConfig));
|
||||
}
|
||||
return context;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class DefaultTestContext implements TestContext {
|
||||
*/
|
||||
@Override
|
||||
public void markApplicationContextDirty(@Nullable HierarchyMode hierarchyMode) {
|
||||
this.cacheAwareContextLoaderDelegate.closeContext(this.mergedContextConfiguration, hierarchyMode);
|
||||
this.cacheAwareContextLoaderDelegate.closeContext(this.mergedConfig, hierarchyMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,7 +245,7 @@ public class DefaultTestContext implements TestContext {
|
||||
.append("testInstance", this.testInstance)
|
||||
.append("testMethod", this.testMethod)
|
||||
.append("testException", this.testException)
|
||||
.append("mergedContextConfiguration", this.mergedContextConfiguration)
|
||||
.append("mergedContextConfiguration", this.mergedConfig)
|
||||
.append("attributes", this.attributes)
|
||||
.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user