org.springframework.test.context.TestContext.markApplicationContextDirty()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(80)

本文整理了Java中org.springframework.test.context.TestContext.markApplicationContextDirty()方法的一些代码示例,展示了TestContext.markApplicationContextDirty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TestContext.markApplicationContextDirty()方法的具体详情如下:
包路径:org.springframework.test.context.TestContext
类名称:TestContext
方法名:markApplicationContextDirty

TestContext.markApplicationContextDirty介绍

[英]Call this method to signal that the ApplicationContext associated with this test context is dirty and should be removed from the context cache.

Do this if a test has modified the context — for example, by modifying the state of a singleton bean, modifying the state of an embedded database, etc.
[中]调用此方法以指示与此测试上下文关联的ApplicationContext为“脏”,应从上下文缓存中删除。
如果测试修改了上下文,那么就这样做——例如,通过修改单例bean的状态、修改嵌入式数据库的状态等等。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Mark the {@linkplain ApplicationContext application context} of the supplied
 * {@linkplain TestContext test context} as
 * {@linkplain TestContext#markApplicationContextDirty(DirtiesContext.HierarchyMode) dirty}
 * and set {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE
 * REINJECT_DEPENDENCIES_ATTRIBUTE} in the test context to {@code true}.
 * @param testContext the test context whose application context should
 * be marked as dirty
 * @param hierarchyMode the context cache clearing mode to be applied if the
 * context is part of a hierarchy; may be {@code null}
 * @since 3.2.2
 */
protected void dirtyContext(TestContext testContext, @Nullable HierarchyMode hierarchyMode) {
  testContext.markApplicationContextDirty(hierarchyMode);
  testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnMethodWithBeforeMethodMode() throws Exception {
  Class<?> clazz = getClass();
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(
    clazz.getDeclaredMethod("dirtiesContextDeclaredLocallyWithBeforeMethodMode"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeClass() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredLocallyBeforeClass.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnMethodWithAfterMethodMode() throws Exception {
  Class<?> clazz = getClass();
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(
    clazz.getDeclaredMethod("dirtiesContextDeclaredLocallyWithAfterMethodMode"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassBeforeEachTestMethod() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredLocallyBeforeEachTestMethod.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredOnMethodViaMetaAnnotationWithAfterMethodMode()
    throws Exception {
  Class<?> clazz = getClass();
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(
    clazz.getDeclaredMethod("dirtiesContextDeclaredViaMetaAnnotationWithAfterMethodMode"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassAfterEachTestMethod() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredLocallyAfterEachTestMethod.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredLocallyAfterClass.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterClass.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverridenAttributes()
    throws Exception {
  Class<?> clazz = DirtiesContextViaMetaAnnotationWithOverridenAttributes.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextViaMetaAnnotationWithOverrides() throws Exception {
  Class<?> clazz = DirtiesContextViaMetaAnnotationWithOverrides.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(CURRENT_LEVEL);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterEachTestMethod()
    throws Exception {
  Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterEachTestMethod.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(1)).markApplicationContextDirty(EXHAUSTIVE);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnMethod() throws Exception {
  Class<?> clazz = getClass();
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredLocallyAfterClass.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterClass.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassBeforeClass() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredLocallyBeforeClass.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean"));
  beforeListener.beforeTestMethod(testContext);
  afterListener.beforeTestMethod(testContext);
  afterListener.afterTestMethod(testContext);
  beforeListener.afterTestMethod(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterEachTestMethod() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredLocallyAfterEachTestMethod.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeEachTestMethod() throws Exception {
  Class<?> clazz = DirtiesContextDeclaredLocallyBeforeEachTestMethod.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterEachTestMethod()
    throws Exception {
  Class<?> clazz = DirtiesContextDeclaredViaMetaAnnotationAfterEachTestMethod.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverrides() throws Exception {
  Class<?> clazz = DirtiesContextViaMetaAnnotationWithOverrides.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  beforeListener.beforeTestClass(testContext);
  afterListener.beforeTestClass(testContext);
  afterListener.afterTestClass(testContext);
  beforeListener.afterTestClass(testContext);
  verify(testContext, times(0)).markApplicationContextDirty(any(HierarchyMode.class));
}

相关文章