org.springframework.test.context

## Class MergedContextConfiguration

- java.lang.Object
- - org.springframework.test.context.MergedContextConfiguration

All Implemented Interfaces:
  Serializable

Direct Known Subclasses:
  WebMergedContextConfiguration

    public class MergedContextConfiguration
    extends Object
    implements Serializable

`MergedContextConfiguration` encapsulates the merged context configuration declared on a test class and all of its superclasses via `@ContextConfiguration` and `@ActiveProfiles`.

Merged resource locations, annotated classes, and active profiles represent all declared values in the test class hierarchy taking into consideration the semantics of the `inheritLocations` and `inheritProfiles` flags in `@ContextConfiguration` and `@ActiveProfiles`, respectively.

A `SmartContextLoader` uses `MergedContextConfiguration` to load an `ApplicationContext`.

`MergedContextConfiguration` is also used by the `TestContext` as the context cache key for caching an `ApplicationContext` that was loaded using properties of this `MergedContextConfiguration`.

Since:
  3.1
Author:
  Sam Brannen
See Also:
  `ContextConfiguration`, `ActiveProfiles`, `ContextConfigurationAttributes`, `SmartContextLoader.loadContext(MergedContextConfiguration)`, Serialized Form

### Constructor Summary

Constructors
Constructor and Description

`MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, ContextLoader contextLoader)`
Create a new `MergedContextConfiguration` instance for the supplied test class, resource locations, annotated classes, context initializers, active profiles, and `ContextLoader`.

`MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, String[] activeProfiles, ContextLoader contextLoader)` Create a new `MergedContextConfiguration` instance for the supplied test class, resource locations, annotated classes, active profiles, and `ContextLoader`.

### Method Summary

Methods
`boolean` `equals(Object obj)` Determine if the supplied object is equal to this `MergedContextConfiguration` instance by comparing both object's locations, annotated classes, context initializer classes, active profiles, and the fully qualified names of their `ContextLoaders`.
`String[]` `getActiveProfiles()` Get the merged active bean definition profiles for the test class.
`Class<?>[]` `getClasses()` Get the merged annotated classes for the test class.
`Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>>` `getContextInitializerClasses()` Get the merged `ApplicationContextInitializer` classes for the test class.
`ContextLoader` `getContextLoader()` Get the resolved `ContextLoader` for the test class.
`String[]` `getLocations()` Get the merged resource locations for the test class.
`Class<?>` `getTestClass()` Get the test class associated with this `MergedContextConfiguration`.
`int` `hashCode()` Generate a unique hash code for all properties of this `MergedContextConfiguration` excluding the test class.
`protected static String` `nullSafeToString(ContextLoader contextLoader)` Generate a null-safe `String` representation of the supplied `ContextLoader` based solely on the fully qualified name of the loader or "null" if the supplied loaded is `null`.
`String` `toString()` Provide a String representation of the test class, locations, annotated classes, context initializer classes, active profiles, and the name of the `ContextLoader`.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### MergedContextConfiguration

    public MergedContextConfiguration(Class<?> testClass,
                              String[] locations,
                              Class<?>[] classes,
                              String[] activeProfiles,
                              ContextLoader contextLoader)

Create a new `MergedContextConfiguration` instance for the supplied test class, resource locations, annotated classes, active profiles, and `ContextLoader`.

If a `null` value is supplied for `locations`, `classes`, or `activeProfiles` an empty array will be stored instead. Furthermore, active profiles will be sorted, and duplicate profiles will be removed.

Parameters:
  `testClass` - the test class for which the configuration was merged
  `locations` - the merged resource locations
  `classes` - the merged annotated classes
  `activeProfiles` - the merged active bean definition profiles
  `contextLoader` - the resolved `ContextLoader`
See Also:
  `MergedContextConfiguration(Class, String[], Class[], Set, String[], ContextLoader)`

#### MergedContextConfiguration

    public MergedContextConfiguration(Class<?> testClass,
                              String[] locations,
                              Class<?>[] classes,
                              Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses,
                              String[] activeProfiles,
                              ContextLoader contextLoader)

Create a new `MergedContextConfiguration` instance for the supplied test class, resource locations, annotated classes, context initializers, active profiles, and `ContextLoader`.

If a `null` value is supplied for `locations`, `classes`, or `activeProfiles` an empty array will be stored instead. If a `null` value is supplied for the `contextInitializerClasses` an empty set will be stored instead. Furthermore, active profiles will be sorted, and duplicate profiles will be removed.

Parameters:
  `testClass` - the test class for which the configuration was merged
  `locations` - the merged resource locations
  `classes` - the merged annotated classes
  `contextInitializerClasses` - the merged context initializer classes
  `activeProfiles` - the merged active bean definition profiles
  `contextLoader` - the resolved `ContextLoader`

### Method Detail

#### nullSafeToString

    protected static String nullSafeToString(ContextLoader contextLoader)

Generate a null-safe `String` representation of the supplied `ContextLoader` based solely on the fully qualified name of the loader or "null" if the supplied loaded is `null`.

#### getTestClass

    public Class<?> getTestClass()

Get the test class associated with this `MergedContextConfiguration`.

#### getLocations

    public String[] getLocations()

Get the merged resource locations for the test class.

#### getClasses

    public Class<?>[] getClasses()

Get the merged annotated classes for the test class.

#### getContextInitializerClasses

    public Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> getContextInitializerClasses()

Get the merged `ApplicationContextInitializer` classes for the test class.

#### getActiveProfiles

    public String[] getActiveProfiles()

Get the merged active bean definition profiles for the test class.

#### getContextLoader

    public ContextLoader getContextLoader()

Get the resolved `ContextLoader` for the test class.

#### hashCode

    public int hashCode()

Generate a unique hash code for all properties of this `MergedContextConfiguration` excluding the test class.

Overrides:
  `hashCode` in class `Object`

#### equals

    public boolean equals(Object obj)

Determine if the supplied object is equal to this `MergedContextConfiguration` instance by comparing both object's locations, annotated classes, context initializer classes, active profiles, and the fully qualified names of their `ContextLoaders`.

Overrides:
  `equals` in class `Object`

#### toString

    public String toString()

Provide a String representation of the test class, locations, annotated classes, context initializer classes, active profiles, and the name of the `ContextLoader`.

Overrides:
  `toString` in class `Object`