public class DefaultTestContext extends java.lang.Object implements TestContext
TestContext interface.| Constructor and Description |
|---|
DefaultTestContext(java.lang.Class<?> testClass,
MergedContextConfiguration mergedContextConfiguration,
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate)
Construct a new
DefaultTestContext from the supplied arguments. |
DefaultTestContext(DefaultTestContext testContext)
Copy constructor for creating a new
DefaultTestContext
based on the attributes and immutable state of the supplied context. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String[] |
attributeNames() |
org.springframework.context.ApplicationContext |
getApplicationContext()
Get the application context for this
test context.
|
java.lang.Object |
getAttribute(java.lang.String name) |
java.lang.Class<?> |
getTestClass()
Get the test class for this test context.
|
java.lang.Throwable |
getTestException()
Get the exception that was thrown during execution
of the test method.
|
java.lang.Object |
getTestInstance()
Get the current test instance for this test context.
|
java.lang.reflect.Method |
getTestMethod()
Get the current test method for this test context.
|
boolean |
hasAttribute(java.lang.String name) |
void |
markApplicationContextDirty(DirtiesContext.HierarchyMode hierarchyMode)
Mark the application context associated
with this test context as dirty (i.e., by removing it from the
context cache and closing it).
|
java.lang.Object |
removeAttribute(java.lang.String name) |
void |
setAttribute(java.lang.String name,
java.lang.Object value) |
java.lang.String |
toString()
Provide a String representation of this test context's state.
|
void |
updateState(java.lang.Object testInstance,
java.lang.reflect.Method testMethod,
java.lang.Throwable testException)
Update this test context to reflect the state of the currently executing test.
|
public DefaultTestContext(DefaultTestContext testContext)
DefaultTestContext
based on the attributes and immutable state of the supplied context.
Immutable state includes all arguments supplied to the standard constructor.
java.lang.NullPointerException - if the supplied DefaultTestContext
is nullpublic DefaultTestContext(java.lang.Class<?> testClass,
MergedContextConfiguration mergedContextConfiguration,
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate)
DefaultTestContext from the supplied arguments.testClass - the test class for this test contextmergedContextConfiguration - the merged application context
configuration for this test contextcacheAwareContextLoaderDelegate - the delegate to use for loading
and closing the application context for this test contextpublic org.springframework.context.ApplicationContext getApplicationContext()
The default implementation delegates to the CacheAwareContextLoaderDelegate
that was supplied when this TestContext was constructed.
getApplicationContext in interface TestContextjava.lang.IllegalStateException - if the context returned by the context
loader delegate is not active (i.e., has been closed).CacheAwareContextLoaderDelegate.loadContext(org.springframework.test.context.MergedContextConfiguration)public void markApplicationContextDirty(@Nullable
DirtiesContext.HierarchyMode hierarchyMode)
The default implementation delegates to the CacheAwareContextLoaderDelegate
that was supplied when this TestContext was constructed.
markApplicationContextDirty in interface TestContexthierarchyMode - the context cache clearing mode to be applied if the
context is part of a hierarchy (may be null)CacheAwareContextLoaderDelegate.closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)public final java.lang.Class<?> getTestClass()
TestContextgetTestClass in interface TestContextnull)public final java.lang.Object getTestInstance()
TestContextNote: this is a mutable property.
getTestInstance in interface TestContextnull)TestContext.updateState(Object, Method, Throwable)public final java.lang.reflect.Method getTestMethod()
TestContextNote: this is a mutable property.
getTestMethod in interface TestContextTestContext.updateState(Object, Method, Throwable)@Nullable public final java.lang.Throwable getTestException()
TestContextNote: this is a mutable property.
getTestException in interface TestContextnull if no exception was thrownTestContext.updateState(Object, Method, Throwable)public void updateState(@Nullable
java.lang.Object testInstance,
@Nullable
java.lang.reflect.Method testMethod,
@Nullable
java.lang.Throwable testException)
TestContextCaution: concurrent invocations of this method might not be thread-safe, depending on the underlying implementation.
updateState in interface TestContexttestInstance - the current test instance (may be null)testMethod - the current test method (may be null)testException - the exception that was thrown in the test method,
or null if no exception was thrownpublic void setAttribute(java.lang.String name,
@Nullable
java.lang.Object value)
setAttribute in interface org.springframework.core.AttributeAccessor@Nullable public java.lang.Object getAttribute(java.lang.String name)
getAttribute in interface org.springframework.core.AttributeAccessor@Nullable public java.lang.Object removeAttribute(java.lang.String name)
removeAttribute in interface org.springframework.core.AttributeAccessorpublic boolean hasAttribute(java.lang.String name)
hasAttribute in interface org.springframework.core.AttributeAccessorpublic java.lang.String[] attributeNames()
attributeNames in interface org.springframework.core.AttributeAccessorpublic java.lang.String toString()
toString in class java.lang.Object