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

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

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

TestContext.getTestClass介绍

[英]Get the Class for this test context.
[中]获取此测试上下文的类。

代码示例

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

@Test
public void missingValueAndScriptsAndStatementsAtMethodLevel() throws Exception {
  Class<?> clazz = MissingValueAndScriptsAndStatementsAtMethodLevel.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo"));
  assertExceptionContains(clazz.getSimpleName() + ".foo" + ".sql");
}

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

private void assertIsRollback(Class<?> clazz, boolean rollback) throws Exception {
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("test"));
  assertEquals(rollback, listener.isRollback(testContext));
}

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

@Test
public void atWebAppConfigTestCaseWithoutExistingRequestAttributes() throws Exception {
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(AtWebAppConfigWebTestCase.class);
  RequestContextHolder.resetRequestAttributes();
  listener.beforeTestClass(testContext);
  assertRequestAttributesDoNotExist();
  assertWebAppConfigTestCase();
}

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

private void assertBeforeTestMethodWithNonTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception {
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  Invocable instance = BeanUtils.instantiateClass(clazz);
  given(testContext.getTestInstance()).willReturn(instance);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest"));
  assertFalse("callback should not have been invoked", instance.invoked());
  TransactionContextHolder.removeCurrentTransactionContext();
  listener.beforeTestMethod(testContext);
  assertFalse("callback should not have been invoked", instance.invoked());
}

代码示例来源: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

private void assertAfterTestMethodWithNonTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception {
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  Invocable instance = BeanUtils.instantiateClass(clazz);
  given(testContext.getTestInstance()).willReturn(instance);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest"));
  assertFalse("callback should not have been invoked", instance.invoked());
  TransactionContextHolder.removeCurrentTransactionContext();
  listener.beforeTestMethod(testContext);
  listener.afterTestMethod(testContext);
  assertFalse("callback should not have been invoked", instance.invoked());
}

代码示例来源: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 missingDataSourceAndTxMgr() throws Exception {
  ApplicationContext ctx = mock(ApplicationContext.class);
  given(ctx.getResource(anyString())).willReturn(mock(Resource.class));
  given(ctx.getAutowireCapableBeanFactory()).willReturn(mock(AutowireCapableBeanFactory.class));
  Class<?> clazz = MissingDataSourceAndTxMgr.class;
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
  given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo"));
  given(testContext.getApplicationContext()).willReturn(ctx);
  assertExceptionContains("supply at least a DataSource or PlatformTransactionManager");
}

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

/**
 * @since 4.3
 */
@Test
public void activateListenerWithoutExistingRequestAttributes() throws Exception {
  BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(NoAtWebAppConfigWebTestCase.class);
  given(testContext.getAttribute(ServletTestExecutionListener.ACTIVATE_LISTENER)).willReturn(true);
  RequestContextHolder.resetRequestAttributes();
  listener.beforeTestClass(testContext);
  assertRequestAttributesDoNotExist();
  assertWebAppConfigTestCase();
}

代码示例来源: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 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 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));
}

代码示例来源: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 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 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);
}

相关文章