类 ContextLoaderUtils

java.lang.Object
cn.taketoday.test.context.support.ContextLoaderUtils

abstract class ContextLoaderUtils extends Object
Utility methods for resolving ContextConfigurationAttributes from the @ContextConfiguration and @ContextHierarchy annotations for use with SmartContextLoaders.
从以下版本开始:
4.0
作者:
Sam Brannen
另请参阅:
  • 字段详细资料

    • GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX

      static final String GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX
      另请参阅:
    • logger

      private static final cn.taketoday.logging.Logger logger
  • 构造器详细资料

    • ContextLoaderUtils

      ContextLoaderUtils()
  • 方法详细资料

    • resolveContextHierarchyAttributes

      static List<List<ContextConfigurationAttributes>> resolveContextHierarchyAttributes(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.

      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)
      返回:
      the list of lists of configuration attributes for the specified class; never null
      抛出:
      IllegalArgumentException - if the supplied class is null; or if neither @ContextConfiguration nor @ContextHierarchy is present on the supplied class
      IllegalStateException - if a test class or composed annotation in the class hierarchy declares both @ContextConfiguration and @ContextHierarchy as top-level annotations.
      从以下版本开始:
      4.0
      另请参阅:
    • buildContextHierarchyMap

      static Map<String,List<ContextConfigurationAttributes>> buildContextHierarchyMap(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.

      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)
      返回:
      a map of context configuration attributes for the context hierarchy, keyed by context hierarchy level name; never null
      抛出:
      IllegalArgumentException - if the lists of context configuration attributes for each level in the @ContextHierarchy do not define unique context configuration within the overall hierarchy.
      从以下版本开始:
      4.0
      另请参阅:
    • resolveContextConfigurationAttributes

      static List<ContextConfigurationAttributes> resolveContextConfigurationAttributes(Class<?> testClass)
      Resolve the list of context configuration attributes for the supplied test class and its superclasses.

      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)
      返回:
      the list of configuration attributes for the specified class, ordered bottom-up (i.e., as if we were traversing up the class hierarchy); never null
      抛出:
      IllegalArgumentException - if the supplied class is null or if @ContextConfiguration is not present on the supplied class
    • hasResources

      private static boolean hasResources(ContextConfiguration contextConfiguration)
    • convertContextConfigToConfigAttributesAndAddToList

      private static void convertContextConfigToConfigAttributesAndAddToList(ContextConfiguration contextConfiguration, Class<?> declaringClass, 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.