提交 197434b3 编写于 作者: S Sam Brannen

Polish TestNG integration tests

上级 81618523
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -171,7 +171,7 @@ public class ClassLevelDirtiesContextTestNGTests {
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class }, inheritListeners = false)
@ContextConfiguration
public static abstract class BaseTestCase extends AbstractTestNGSpringContextTests {
static abstract class BaseTestCase extends AbstractTestNGSpringContextTests {
@Configuration
static class Config {
......@@ -189,75 +189,75 @@ public class ClassLevelDirtiesContextTestNGTests {
}
}
public static final class CleanTestCase extends BaseTestCase {
static final class CleanTestCase extends BaseTestCase {
@org.testng.annotations.Test
public void verifyContextWasAutowired() {
void verifyContextWasAutowired() {
assertApplicationContextWasAutowired();
}
}
@DirtiesContext
public static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends BaseTestCase {
static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends BaseTestCase {
@org.testng.annotations.Test
public void verifyContextWasAutowired() {
void verifyContextWasAutowired() {
assertApplicationContextWasAutowired();
}
}
public static class InheritedClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends
static class InheritedClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends
ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase {
}
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public static class ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends BaseTestCase {
static class ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends BaseTestCase {
@org.testng.annotations.Test
public void verifyContextWasAutowired() {
void verifyContextWasAutowired() {
assertApplicationContextWasAutowired();
}
}
public static class InheritedClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends
static class InheritedClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends
ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase {
}
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public static class ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends BaseTestCase {
static class ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends BaseTestCase {
@org.testng.annotations.Test
public void verifyContextWasAutowired1() {
void verifyContextWasAutowired1() {
assertApplicationContextWasAutowired();
}
@org.testng.annotations.Test
public void verifyContextWasAutowired2() {
void verifyContextWasAutowired2() {
assertApplicationContextWasAutowired();
}
@org.testng.annotations.Test
public void verifyContextWasAutowired3() {
void verifyContextWasAutowired3() {
assertApplicationContextWasAutowired();
}
}
public static class InheritedClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends
static class InheritedClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends
ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase {
}
@DirtiesContext
public static class ClassLevelDirtiesContextWithDirtyMethodsTestCase extends BaseTestCase {
static class ClassLevelDirtiesContextWithDirtyMethodsTestCase extends BaseTestCase {
@org.testng.annotations.Test
@DirtiesContext
public void dirtyContext() {
void dirtyContext() {
assertApplicationContextWasAutowired();
}
}
public static class InheritedClassLevelDirtiesContextWithDirtyMethodsTestCase extends
static class InheritedClassLevelDirtiesContextWithDirtyMethodsTestCase extends
ClassLevelDirtiesContextWithDirtyMethodsTestCase {
}
......
......@@ -54,8 +54,8 @@ import static org.testng.Assert.*;
* @since 3.1
*/
@ContextConfiguration
public class AnnotationConfigTransactionalTestNGSpringContextTests extends
AbstractTransactionalTestNGSpringContextTests {
public class AnnotationConfigTransactionalTestNGSpringContextTests
extends AbstractTransactionalTestNGSpringContextTests {
private static final String JANE = "jane";
private static final String SUE = "sue";
......@@ -94,7 +94,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
}
@BeforeClass
public void beforeClass() {
void beforeClass() {
numSetUpCalls = 0;
numSetUpCallsInTransaction = 0;
numTearDownCalls = 0;
......@@ -102,7 +102,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
}
@AfterClass
public void afterClass() {
void afterClass() {
assertEquals(numSetUpCalls, NUM_TESTS, "number of calls to setUp().");
assertEquals(numSetUpCallsInTransaction, NUM_TX_TESTS, "number of calls to setUp() within a transaction.");
assertEquals(numTearDownCalls, NUM_TESTS, "number of calls to tearDown().");
......@@ -111,7 +111,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void autowiringFromConfigClass() {
void autowiringFromConfigClass() {
assertNotNull(employee, "The employee should have been autowired.");
assertEquals(employee.getName(), "John Smith");
......@@ -126,7 +126,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
}
@BeforeMethod
public void setUp() throws Exception {
void setUp() throws Exception {
numSetUpCalls++;
if (inTransaction()) {
numSetUpCallsInTransaction++;
......@@ -143,7 +143,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
}
@AfterMethod
public void tearDown() throws Exception {
void tearDown() throws Exception {
numTearDownCalls++;
if (inTransaction()) {
numTearDownCallsInTransaction++;
......@@ -162,7 +162,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
static class ContextConfiguration {
@Bean
public Employee employee() {
Employee employee() {
Employee employee = new Employee();
employee.setName("John Smith");
employee.setAge(42);
......@@ -171,17 +171,17 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
}
@Bean
public Pet pet() {
Pet pet() {
return new Pet("Fido");
}
@Bean
public PlatformTransactionManager transactionManager() {
PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.addScript("classpath:/org/springframework/test/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/jdbc/data.sql")//
......
......@@ -117,7 +117,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@BeforeClass
public void beforeClass() {
void beforeClass() {
numSetUpCalls = 0;
numSetUpCallsInTransaction = 0;
numTearDownCalls = 0;
......@@ -125,7 +125,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@AfterClass
public void afterClass() {
void afterClass() {
assertEquals(numSetUpCalls, NUM_TESTS, "number of calls to setUp().");
assertEquals(numSetUpCallsInTransaction, NUM_TX_TESTS, "number of calls to setUp() within a transaction.");
assertEquals(numTearDownCalls, NUM_TESTS, "number of calls to tearDown().");
......@@ -134,7 +134,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyApplicationContextSet() {
void verifyApplicationContextSet() {
assertInTransaction(false);
assertNotNull(super.applicationContext,
"The application context should have been set due to ApplicationContextAware semantics.");
......@@ -144,7 +144,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyBeanInitialized() {
void verifyBeanInitialized() {
assertInTransaction(false);
assertTrue(beanInitialized,
"This test instance should have been initialized due to InitializingBean semantics.");
......@@ -152,7 +152,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyBeanNameSet() {
void verifyBeanNameSet() {
assertInTransaction(false);
assertEquals(beanName, getClass().getName(),
"The bean name of this test instance should have been set due to BeanNameAware semantics.");
......@@ -160,7 +160,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyAnnotationAutowiredFields() {
void verifyAnnotationAutowiredFields() {
assertInTransaction(false);
assertNull(nonrequiredLong, "The nonrequiredLong field should NOT have been autowired.");
assertNotNull(pet, "The pet field should have been autowired.");
......@@ -169,7 +169,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyAnnotationAutowiredMethods() {
void verifyAnnotationAutowiredMethods() {
assertInTransaction(false);
assertNotNull(employee, "The setEmployee() method should have been autowired.");
assertEquals(employee.getName(), "John Smith", "employee's name.");
......@@ -177,14 +177,14 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyResourceAnnotationInjectedFields() {
void verifyResourceAnnotationInjectedFields() {
assertInTransaction(false);
assertEquals(foo, "Foo", "The foo field should have been injected via @Resource.");
}
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyResourceAnnotationInjectedMethods() {
void verifyResourceAnnotationInjectedMethods() {
assertInTransaction(false);
assertEquals(bar, "Bar", "The setBar() method should have been injected via @Resource.");
}
......@@ -196,7 +196,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@BeforeMethod
public void setUp() throws Exception {
void setUp() throws Exception {
numSetUpCalls++;
if (inTransaction()) {
numSetUpCallsInTransaction++;
......@@ -213,7 +213,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@AfterMethod
public void tearDown() throws Exception {
void tearDown() throws Exception {
numTearDownCalls++;
if (inTransaction()) {
numTearDownCallsInTransaction++;
......
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -57,7 +57,7 @@ public class ServletTestExecutionListenerTestNGIntegrationTests extends Abstract
* @see #ensureMocksAreReinjectedBetweenTests_2
*/
@Test
public void ensureMocksAreReinjectedBetweenTests_1() {
void ensureMocksAreReinjectedBetweenTests_1() {
assertInjectedServletRequestEqualsRequestInRequestContextHolder();
}
......@@ -67,7 +67,7 @@ public class ServletTestExecutionListenerTestNGIntegrationTests extends Abstract
* @see #ensureMocksAreReinjectedBetweenTests_1
*/
@Test
public void ensureMocksAreReinjectedBetweenTests_2() {
void ensureMocksAreReinjectedBetweenTests_2() {
assertInjectedServletRequestEqualsRequestInRequestContextHolder();
}
......
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -52,34 +52,34 @@ public class TestNGSpringContextWebTests extends AbstractTestNGSpringContextTest
static class Config {
@Bean
public String foo() {
String foo() {
return "enigma";
}
}
protected ServletContext servletContext;
ServletContext servletContext;
@Autowired
protected WebApplicationContext wac;
WebApplicationContext wac;
@Autowired
protected MockServletContext mockServletContext;
MockServletContext mockServletContext;
@Autowired
protected MockHttpServletRequest request;
MockHttpServletRequest request;
@Autowired
protected MockHttpServletResponse response;
MockHttpServletResponse response;
@Autowired
protected MockHttpSession session;
MockHttpSession session;
@Autowired
protected ServletWebRequest webRequest;
ServletWebRequest webRequest;
@Autowired
protected String foo;
String foo;
@Override
......@@ -88,7 +88,7 @@ public class TestNGSpringContextWebTests extends AbstractTestNGSpringContextTest
}
@Test
public void basicWacFeatures() throws Exception {
void basicWacFeatures() throws Exception {
assertNotNull("ServletContext should be set in the WAC.", wac.getServletContext());
assertNotNull("ServletContext should have been set via ServletContextAware.", servletContext);
......@@ -112,7 +112,7 @@ public class TestNGSpringContextWebTests extends AbstractTestNGSpringContextTest
}
@Test
public void fooEnigmaAutowired() {
void fooEnigmaAutowired() {
assertEquals("enigma", foo);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册