abstract class ContextLoaderUtils
extends java.lang.Object
ContextConfigurationAttributes
from the
@ContextConfiguration
and
@ContextHierarchy
annotations for use with
SmartContextLoaders
.SmartContextLoader
,
ContextConfigurationAttributes
,
ContextConfiguration
,
ContextHierarchy
Modifier and Type | Field and Description |
---|---|
(package private) static java.lang.String |
GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX |
private static Log |
logger |
Modifier | Constructor and Description |
---|---|
private |
ContextLoaderUtils() |
Modifier and Type | Method and Description |
---|---|
(package private) static java.util.Map<java.lang.String,java.util.List<ContextConfigurationAttributes>> |
buildContextHierarchyMap(java.lang.Class<?> testClass)
Build a context hierarchy map for the supplied test class and its superclasses, taking into account context hierarchies
declared via
@ContextHierarchy and
@ContextConfiguration . |
private static void |
convertContextConfigToConfigAttributesAndAddToList(ContextConfiguration contextConfiguration,
java.lang.Class<?> declaringClass,
java.util.List<ContextConfigurationAttributes> attributesList)
Convenience method for creating a
ContextConfigurationAttributes
instance from the supplied ContextConfiguration annotation and
declaring class and then adding the attributes to the supplied list. |
(package private) static java.util.List<ContextConfigurationAttributes> |
resolveContextConfigurationAttributes(java.lang.Class<?> testClass)
Resolve the list of context
configuration attributes for the supplied test class and its
superclasses.
|
(package private) static java.util.List<java.util.List<ContextConfigurationAttributes>> |
resolveContextHierarchyAttributes(java.lang.Class<?> testClass)
Resolve the list of lists of context
configuration attributes for the supplied test class and its
superclasses, taking into account context hierarchies declared via
@ContextHierarchy and
@ContextConfiguration . |
static final java.lang.String GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX
private static final Log logger
static java.util.List<java.util.List<ContextConfigurationAttributes>> resolveContextHierarchyAttributes(java.lang.Class<?> testClass)
@ContextHierarchy
and
@ContextConfiguration
.
The outer list represents a top-down ordering of context configuration
attributes, where each element in the list represents the context configuration
declared on a given test class in the class hierarchy. Each nested list
contains the context configuration attributes declared either via a single
instance of @ContextConfiguration
on the particular class or via
multiple instances of @ContextConfiguration
declared within a
single @ContextHierarchy
instance on the particular class.
Furthermore, each nested list maintains the order in which
@ContextConfiguration
instances are declared.
Note that the inheritLocations
and
inheritInitializers
flags of
@ContextConfiguration
will not
be taken into consideration. If these flags need to be honored, that must be
handled manually when traversing the nested lists returned by this method.
testClass
- the class for which to resolve the context hierarchy attributes
(must not be null
)null
java.lang.IllegalArgumentException
- if the supplied class is null
; if
neither @ContextConfiguration
nor @ContextHierarchy
is
present on the supplied class; or if a test class or composed annotation
in the class hierarchy declares both @ContextConfiguration
and
@ContextHierarchy
as top-level annotations.java.lang.IllegalStateException
- if no class in the class hierarchy declares
@ContextHierarchy
.buildContextHierarchyMap(Class)
,
resolveContextConfigurationAttributes(Class)
static java.util.Map<java.lang.String,java.util.List<ContextConfigurationAttributes>> buildContextHierarchyMap(java.lang.Class<?> testClass)
@ContextHierarchy
and
@ContextConfiguration
.
Each value in the map represents the consolidated list of context configuration attributes for a
given level in the context hierarchy (potentially across the test class
hierarchy), keyed by the name
of the
context hierarchy level.
If a given level in the context hierarchy does not have an explicit
name (i.e., configured via ContextConfiguration.name()
), a name will
be generated for that hierarchy level by appending the numerical level to
the GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX
.
testClass
- the class for which to resolve the context hierarchy map
(must not be null
)null
java.lang.IllegalArgumentException
- if the lists of context configuration
attributes for each level in the @ContextHierarchy
do not define
unique context configuration within the overall hierarchy.resolveContextHierarchyAttributes(Class)
static java.util.List<ContextConfigurationAttributes> resolveContextConfigurationAttributes(java.lang.Class<?> testClass)
Note that the inheritLocations
and
inheritInitializers
flags of
@ContextConfiguration
will not
be taken into consideration. If these flags need to be honored, that must be
handled manually when traversing the list returned by this method.
testClass
- the class for which to resolve the configuration attributes (must
not be null
)null
java.lang.IllegalArgumentException
- if the supplied class is null
or if
@ContextConfiguration
is not present on the supplied classprivate static void convertContextConfigToConfigAttributesAndAddToList(ContextConfiguration contextConfiguration, java.lang.Class<?> declaringClass, java.util.List<ContextConfigurationAttributes> attributesList)
ContextConfigurationAttributes
instance from the supplied ContextConfiguration
annotation and
declaring class and then adding the attributes to the supplied list.