Cache default EnclosingConfiguration mode in TestContextAnnotationUtils
This commit is contained in:
@@ -75,6 +75,7 @@ public abstract class TestContextAnnotationUtils {
|
|||||||
private static final ConcurrentLruCache<Class<?>, EnclosingConfiguration> cachedEnclosingConfigurationModes =
|
private static final ConcurrentLruCache<Class<?>, EnclosingConfiguration> cachedEnclosingConfigurationModes =
|
||||||
new ConcurrentLruCache<>(32, TestContextAnnotationUtils::lookUpEnclosingConfiguration);
|
new ConcurrentLruCache<>(32, TestContextAnnotationUtils::lookUpEnclosingConfiguration);
|
||||||
|
|
||||||
|
private static EnclosingConfiguration defaultEnclosingConfigurationMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the first annotation of the specified {@code annotationType} within
|
* Find the first annotation of the specified {@code annotationType} within
|
||||||
@@ -384,6 +385,10 @@ public abstract class TestContextAnnotationUtils {
|
|||||||
getEnclosingConfiguration(clazz) == EnclosingConfiguration.INHERIT);
|
getEnclosingConfiguration(clazz) == EnclosingConfiguration.INHERIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void clearCaches() {
|
||||||
|
defaultEnclosingConfigurationMode = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link EnclosingConfiguration} mode for the supplied class.
|
* Get the {@link EnclosingConfiguration} mode for the supplied class.
|
||||||
* @param clazz the class for which the enclosing configuration mode should
|
* @param clazz the class for which the enclosing configuration mode should
|
||||||
@@ -405,9 +410,13 @@ public abstract class TestContextAnnotationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static EnclosingConfiguration getDefaultEnclosingConfigurationMode() {
|
private static EnclosingConfiguration getDefaultEnclosingConfigurationMode() {
|
||||||
String value = SpringProperties.getProperty(NestedTestConfiguration.ENCLOSING_CONFIGURATION_PROPERTY_NAME);
|
if (defaultEnclosingConfigurationMode == null) {
|
||||||
EnclosingConfiguration enclosingConfigurationMode = EnclosingConfiguration.from(value);
|
String value = SpringProperties.getProperty(NestedTestConfiguration.ENCLOSING_CONFIGURATION_PROPERTY_NAME);
|
||||||
return (enclosingConfigurationMode != null ? enclosingConfigurationMode : EnclosingConfiguration.INHERIT);
|
EnclosingConfiguration enclosingConfigurationMode = EnclosingConfiguration.from(value);
|
||||||
|
defaultEnclosingConfigurationMode =
|
||||||
|
(enclosingConfigurationMode != null ? enclosingConfigurationMode : EnclosingConfiguration.INHERIT);
|
||||||
|
}
|
||||||
|
return defaultEnclosingConfigurationMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertNonEmptyAnnotationTypeArray(Class<?>[] annotationTypes, String message) {
|
private static void assertNonEmptyAnnotationTypeArray(Class<?>[] annotationTypes, String message) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -55,6 +56,11 @@ class TestContextAnnotationUtilsTests {
|
|||||||
@DisplayName("searchEnclosingClass() tests")
|
@DisplayName("searchEnclosingClass() tests")
|
||||||
class SearchEnclosingClassTests {
|
class SearchEnclosingClassTests {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void clearCaches() {
|
||||||
|
TestContextAnnotationUtils.clearCaches();
|
||||||
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void clearGlobalFlag() {
|
void clearGlobalFlag() {
|
||||||
setGlobalFlag(null);
|
setGlobalFlag(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user