class DefaultTestContext extends AttributeAccessorSupport implements TestContext
TestContext
interface.
Although DefaultTestContext
was first introduced in Spring Framework
4.0, the initial implementation of this class was extracted from the existing
code base for TestContext
when TestContext
was converted into
an interface.
Modifier and Type | Field and Description |
---|---|
private CacheAwareContextLoaderDelegate |
cacheAwareContextLoaderDelegate |
private MergedContextConfiguration |
mergedContextConfiguration |
private static long |
serialVersionUID |
private java.lang.Class<?> |
testClass |
private java.lang.Throwable |
testException |
private java.lang.Object |
testInstance |
private java.lang.reflect.Method |
testMethod |
Constructor and Description |
---|
DefaultTestContext(TestContextBootstrapper testContextBootstrapper)
Construct a new test context using the supplied
TestContextBootstrapper . |
Modifier and Type | Method and Description |
---|---|
ApplicationContext |
getApplicationContext()
Get the
application context for this test
context, possibly cached. |
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. |
void |
markApplicationContextDirty(DirtiesContext.HierarchyMode hierarchyMode)
Call this method to signal that the application
context associated with this test context is dirty and should be
discarded.
|
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.
|
attributeNames, copyAttributesFrom, equals, getAttribute, hasAttribute, hashCode, removeAttribute, setAttribute
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
attributeNames, getAttribute, hasAttribute, removeAttribute, setAttribute
private static final long serialVersionUID
private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate
private final MergedContextConfiguration mergedContextConfiguration
private final java.lang.Class<?> testClass
private java.lang.Object testInstance
private java.lang.reflect.Method testMethod
private java.lang.Throwable testException
DefaultTestContext(TestContextBootstrapper testContextBootstrapper)
TestContextBootstrapper
.testContextBootstrapper
- the TestContextBootstrapper
to use
to construct the test context (must not be null
)public ApplicationContext getApplicationContext()
application context
for this test
context, possibly cached.
Implementations of this method are responsible for loading the application context if the corresponding context has not already been loaded, potentially caching the context as well.
getApplicationContext
in interface TestContext
public void markApplicationContextDirty(DirtiesContext.HierarchyMode hierarchyMode)
markApplicationContextDirty
in interface TestContext
hierarchyMode
- the context cache clearing mode to be applied if the
context is part of a hierarchy (may be null
)public final java.lang.Class<?> getTestClass()
test class
for this test context.getTestClass
in interface TestContext
null
)public final java.lang.Object getTestInstance()
test instance
for this test context.
Note: this is a mutable property.
getTestInstance
in interface TestContext
null
)TestContext.updateState(Object, Method, Throwable)
public final java.lang.reflect.Method getTestMethod()
test method
for this test context.
Note: this is a mutable property.
getTestMethod
in interface TestContext
null
)TestContext.updateState(Object, Method, Throwable)
public final java.lang.Throwable getTestException()
exception
that was thrown during execution of
the test method
.
Note: this is a mutable property.
getTestException
in interface TestContext
null
if no
exception was thrownTestContext.updateState(Object, Method, Throwable)
public void updateState(java.lang.Object testInstance, java.lang.reflect.Method testMethod, java.lang.Throwable testException)
Caution: concurrent invocations of this method might not be thread-safe, depending on the underlying implementation.
updateState
in interface TestContext
testInstance
- 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 java.lang.String toString()
toString
in class java.lang.Object