类 DefaultTestContext
- java.lang.Object
- org.springframework.test.context.support.DefaultTestContext
- 所有已实现的接口:
Serializable,AttributeAccessor,TestContext
public class DefaultTestContext extends Object implements TestContext
Default implementation of theTestContextinterface.- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Juergen Hoeller, Rob Harrop
- 另请参阅:
- 序列化表格
构造器概要
构造器 构造器 说明 DefaultTestContext(Class<?> testClass, MergedContextConfiguration mergedContextConfiguration, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate)Construct a newDefaultTestContextfrom the supplied arguments.DefaultTestContext(DefaultTestContext testContext)Copy constructor for creating a newDefaultTestContextbased on the attributes and immutable state of the supplied context.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 String[]attributeNames()Return the names of all attributes.ApplicationContextgetApplicationContext()Get the application context for this test context.ObjectgetAttribute(String name)Get the value of the attribute identified byname.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.booleanhasApplicationContext()Determine if the application context for this test context is present in the context cache.booleanhasAttribute(String name)Returntrueif the attribute identified bynameexists.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).ObjectremoveAttribute(String name)Remove the attribute identified bynameand return its value.voidsetAttribute(String name, Object value)Set the attribute defined bynameto the suppliedvalue.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.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口继承的方法 org.springframework.test.context.TestContext
publishEvent
构造器详细资料
DefaultTestContext
public DefaultTestContext(DefaultTestContext testContext)
Copy constructor for creating a newDefaultTestContextbased on the attributes and immutable state of the supplied context.Immutable state includes all arguments supplied to the standard constructor.
- 抛出:
NullPointerException- if the suppliedDefaultTestContextisnull
DefaultTestContext
public DefaultTestContext(Class<?> testClass, MergedContextConfiguration mergedContextConfiguration, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate)
Construct a newDefaultTestContextfrom 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 context
方法详细资料
hasApplicationContext
public boolean hasApplicationContext()
Determine if the application context for this test context is present in the context cache.- 指定者:
hasApplicationContext在接口中TestContext- 返回:
trueif the application context has already been loaded and stored in the context cache- 从以下版本开始:
- 5.2
- 另请参阅:
getApplicationContext(),CacheAwareContextLoaderDelegate.isContextLoaded(org.springframework.test.context.MergedContextConfiguration)
getApplicationContext
public ApplicationContext getApplicationContext()
Get the application context for this test context.The default implementation delegates to the
CacheAwareContextLoaderDelegatethat was supplied when thisTestContextwas constructed.- 指定者:
getApplicationContext在接口中TestContext- 返回:
- the application context (never
null) - 抛出:
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)
markApplicationContextDirty
public void markApplicationContextDirty(@Nullable 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.- 指定者:
markApplicationContextDirty在接口中TestContext- 参数:
hierarchyMode- the context cache clearing mode to be applied if the context is part of a hierarchy (may benull)- 另请参阅:
CacheAwareContextLoaderDelegate.closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
getTestClass
public final Class<?> getTestClass()
从接口复制的说明:TestContextGet the test class for this test context.- 指定者:
getTestClass在接口中TestContext- 返回:
- the test class (never
null)
getTestInstance
public final Object getTestInstance()
从接口复制的说明:TestContextGet the current test instance for this test context.Note: this is a mutable property.
- 指定者:
getTestInstance在接口中TestContext- 返回:
- the current test instance (never
null) - 另请参阅:
TestContext.updateState(Object, Method, Throwable)
getTestMethod
public final Method getTestMethod()
从接口复制的说明:TestContextGet the current test method for this test context.Note: this is a mutable property.
- 指定者:
getTestMethod在接口中TestContext- 返回:
- the current test method (never
null) - 另请参阅:
TestContext.updateState(Object, Method, Throwable)
getTestException
@Nullable public final Throwable getTestException()
从接口复制的说明:TestContextGet the exception that was thrown during execution of the test method.Note: this is a mutable property.
- 指定者:
getTestException在接口中TestContext- 返回:
- the exception that was thrown, or
nullif no exception was thrown - 另请参阅:
TestContext.updateState(Object, Method, Throwable)
updateState
public void updateState(@Nullable Object testInstance, @Nullable Method testMethod, @Nullable Throwable testException)
从接口复制的说明:TestContextUpdate this test context to reflect the state of the currently executing test.WARNING: This method should only be invoked by the
TestContextManager.Caution: concurrent invocations of this method might not be thread-safe, depending on the underlying implementation.
- 指定者:
updateState在接口中TestContext- 参数:
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
setAttribute
public void setAttribute(String name, @Nullable Object value)
从接口复制的说明:AttributeAccessorSet the attribute defined bynameto the suppliedvalue. Ifvalueisnull, the attribute isremoved.In general, users should take care to prevent overlaps with other metadata attributes by using fully-qualified names, perhaps using class or package names as prefix.
- 指定者:
setAttribute在接口中AttributeAccessor- 参数:
name- the unique attribute keyvalue- the attribute value to be attached
getAttribute
@Nullable public Object getAttribute(String name)
从接口复制的说明:AttributeAccessorGet the value of the attribute identified byname. Returnnullif the attribute doesn't exist.- 指定者:
getAttribute在接口中AttributeAccessor- 参数:
name- the unique attribute key- 返回:
- the current value of the attribute, if any
removeAttribute
@Nullable public Object removeAttribute(String name)
从接口复制的说明:AttributeAccessorRemove the attribute identified bynameand return its value. Returnnullif no attribute undernameis found.- 指定者:
removeAttribute在接口中AttributeAccessor- 参数:
name- the unique attribute key- 返回:
- the last value of the attribute, if any
hasAttribute
public boolean hasAttribute(String name)
从接口复制的说明:AttributeAccessorReturntrueif the attribute identified bynameexists. Otherwise returnfalse.- 指定者:
hasAttribute在接口中AttributeAccessor- 参数:
name- the unique attribute key
attributeNames
public String[] attributeNames()
从接口复制的说明:AttributeAccessorReturn the names of all attributes.- 指定者:
attributeNames在接口中AttributeAccessor