Class DefaultTestContext
- java.lang.Object
- org.springframework.core.AttributeAccessorSupport
- org.springframework.test.context.support.DefaultTestContext
- All Implemented Interfaces:
Serializable,AttributeAccessor,TestContext
public class DefaultTestContext extends AttributeAccessorSupport implements TestContext
Default implementation of theTestContextinterface.- Since:
- 4.0
- Author:
- Sam Brannen, Juergen Hoeller
- See Also:
- Serialized Form
Constructor Summary
Constructors Constructor Description DefaultTestContext(Class<?> testClass, MergedContextConfiguration mergedContextConfiguration, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate)Construct a newDefaultTestContextfrom the supplied arguments.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ApplicationContextgetApplicationContext()Get the application context for this test context.Class<?>getTestClass()Get the test class for this test context.ThrowablegetTestException()Get the exception that was thrown during execution of the test method.ObjectgetTestInstance()Get the current test instance for this test context.MethodgetTestMethod()Get the current test method for this test context.voidmarkApplicationContextDirty(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).StringtoString()Provide a String representation of this test context's state.voidupdateState(Object testInstance, Method testMethod, Throwable testException)Update this test context to reflect the state of the currently executing test.Methods inherited from class org.springframework.core.AttributeAccessorSupport
attributeNames, copyAttributesFrom, equals, getAttribute, hasAttribute, hashCode, removeAttribute, setAttribute
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.core.AttributeAccessor
attributeNames, getAttribute, hasAttribute, removeAttribute, setAttribute
Constructor Detail
DefaultTestContext
public DefaultTestContext(Class<?> testClass, MergedContextConfiguration mergedContextConfiguration, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate)
Construct a newDefaultTestContextfrom the supplied arguments.- Parameters:
testClass- the test class for this test context; nevernullmergedContextConfiguration- the merged application context configuration for this test context; nevernullcacheAwareContextLoaderDelegate- the delegate to use for loading and closing the application context for this test context; nevernull
Method Detail
getApplicationContext
public ApplicationContext getApplicationContext()
Get the application context for this test context.The default implementation delegates to the
CacheAwareContextLoaderDelegatethat was supplied when thisTestContextwas constructed.- Specified by:
getApplicationContextin interfaceTestContext- Returns:
- the application context (never
null) - Throws:
IllegalStateException- if the context returned by the context loader delegate is not active (i.e., has been closed).- See Also:
CacheAwareContextLoaderDelegate.loadContext(org.springframework.test.context.MergedContextConfiguration)
markApplicationContextDirty
public 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).The default implementation delegates to the
CacheAwareContextLoaderDelegatethat was supplied when thisTestContextwas constructed.- Specified by:
markApplicationContextDirtyin interfaceTestContext- Parameters:
hierarchyMode- the context cache clearing mode to be applied if the context is part of a hierarchy (may benull)- See Also:
CacheAwareContextLoaderDelegate.closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
getTestClass
public final Class<?> getTestClass()
Description copied from interface:TestContextGet the test class for this test context.- Specified by:
getTestClassin interfaceTestContext- Returns:
- the test class (never
null)
getTestInstance
public final Object getTestInstance()
Description copied from interface:TestContextGet the current test instance for this test context.Note: this is a mutable property.
- Specified by:
getTestInstancein interfaceTestContext- Returns:
- the current test instance (may be
null) - See Also:
TestContext.updateState(Object, Method, Throwable)
getTestMethod
public final Method getTestMethod()
Description copied from interface:TestContextGet the current test method for this test context.Note: this is a mutable property.
- Specified by:
getTestMethodin interfaceTestContext- Returns:
- the current test method (may be
null) - See Also:
TestContext.updateState(Object, Method, Throwable)
getTestException
public final Throwable getTestException()
Description copied from interface:TestContextGet the exception that was thrown during execution of the test method.Note: this is a mutable property.
- Specified by:
getTestExceptionin interfaceTestContext- Returns:
- the exception that was thrown, or
nullif no exception was thrown - See Also:
TestContext.updateState(Object, Method, Throwable)
updateState
public void updateState(Object testInstance, Method testMethod, Throwable testException)
Description copied from interface:TestContextUpdate this test context to reflect the state of the currently executing test.Caution: concurrent invocations of this method might not be thread-safe, depending on the underlying implementation.
- Specified by:
updateStatein interfaceTestContext- Parameters:
testInstance- the current test instance (may benull)testMethod- the current test method (may benull)testException- the exception that was thrown in the test method, ornullif no exception was thrown