diff --git a/spring-framework-reference/src/testing.xml b/spring-framework-reference/src/testing.xml
index 171a5e1bbc1..3861198bdfe 100644
--- a/spring-framework-reference/src/testing.xml
+++ b/spring-framework-reference/src/testing.xml
@@ -429,8 +429,8 @@
load and configure an
ApplicationContext for test classes.
Specifically, @ContextConfiguration
- declares either the application context resource
- locations or the
+ declares either the application context
+ resource locationsor the
@Configurationclasses to load as well as the
ContextLoader strategy to use for
@@ -439,18 +439,28 @@
either resource locations or configuration
classes.
- @ContextConfiguration(locations="example/test-context.xml", loader=CustomContextLoader.class)
-public class CustomConfiguredApplicationContextTests {
+ @ContextConfiguration(locations="example/test-context.xml", loader=CustomContextLoader.class)
+public class XmlApplicationContextTests {
+ // class body...
+}
+
+ @ContextConfiguration(classes=MyConfig.class)
+public class ConfigClassApplicationContextTests {
// class body...
}@ContextConfiguration
- supports inherited resource locations by
- default. See Context
- management and caching and Javadoc for an example and
- further details.
+ provides support for inheriting resource
+ locations or configuration classes by default.
+
+ See Context
+ management and caching and Javadoc for examples and further
+ details.
@@ -497,17 +507,18 @@ public class CustomConfiguredApplicationContextTests {
AFTER_EACH_TEST_METHOD, the context is marked
dirty after each test method in the class.
- @DirtiesContext
+ @DirtiesContext
public class ContextDirtyingTests {
// some tests that result in the Spring container being dirtied
}
- @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+ @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class ContextDirtyingTests {
// some tests that result in the Spring container being dirtied
}
- @DirtiesContext
+ @DirtiesContext
@Test
public void testProcessWhichDirtiesAppCtx() {
// some logic that results in the Spring container being dirtied
@@ -532,7 +543,7 @@ public void testProcessWhichDirtiesAppCtx() {
@ContextConfiguration.
@ContextConfiguration
-@TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class})
+@TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class})
public class CustomTestExecutionListenerTests {
// class body...
}
@@ -559,7 +570,9 @@ public class CustomTestExecutionListenerTests {
@ContextConfiguration.
@ContextConfiguration
-@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)
+@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)
public class CustomConfiguredTransactionalTests {
// class body...
}
@@ -587,7 +600,7 @@ public class CustomConfiguredTransactionalTests {
@Rollback to override the default
rollback flag configured at the class level.
- @Rollback(false)
+ @Rollback(false)
@Test
public void testProcessWithoutRollback() {
// ...
@@ -604,8 +617,8 @@ public void testProcessWithoutRollback() {
via the @Transactional
annotation.
- @BeforeTransaction
-public void beforeTransaction() {
+ @BeforeTransaction
+public void beforeTransaction() {
// logic to be executed before a transaction is started
}
@@ -620,8 +633,8 @@ public void beforeTransaction() {
via the @Transactional
annotation.
- @AfterTransaction
-public void afterTransaction() {
+ @AfterTransaction
+public void afterTransaction() {
// logic to be executed after a transaction has ended
}
@@ -634,7 +647,7 @@ public void afterTransaction() {
test method must not execute in a transactional
context.
- @NotTransactional
+ @NotTransactional
@Test
public void testProcessWithoutTransaction() {
// ...
@@ -679,7 +692,8 @@ public void testProcessWithoutTransaction() {
class or to individual methods. Class-level usage overrides
method-level usage.
- @IfProfileValue(name="java.vendor", value="Sun Microsystems Inc.")
+ @IfProfileValue(name="java.vendor", value="Sun Microsystems Inc.")
@Test
public void testProcessWhichRunsOnlyOnSunJvm() {
// some logic that should run only on Java VMs from Sun Microsystems
@@ -691,7 +705,8 @@ public void testProcessWhichRunsOnlyOnSunJvm() {
to achieve TestNG-like support for test groups
in a JUnit environment. Consider the following example:
- @IfProfileValue(name="test-groups", values={"unit-tests", "integration-tests"})
+ @IfProfileValue(name="test-groups", values={"unit-tests", "integration-tests"})
@Test
public void testProcessWhichRunsForUnitOrIntegrationTestGroups() {
// some logic that should run only for unit and integration test groups
@@ -711,7 +726,7 @@ public void testProcessWhichRunsForUnitOrIntegrationTestGroups() {
SystemProfileValueSource is used by
default.
- @ProfileValueSourceConfiguration(CustomProfileValueSource.class)
+ @ProfileValueSourceConfiguration(CustomProfileValueSource.class)
public class CustomProfileValueSourceTests {
// class body...
}
@@ -731,7 +746,7 @@ public class CustomProfileValueSourceTests {
set up or tear down of the
test fixture.
- @Timed(millis=1000)
+ @Timed(millis=1000)
public void testProcessWithOneSecondTimeout() {
// some logic that should not take longer than 1 second to execute
}
@@ -763,7 +778,7 @@ public void testProcessWithOneSecondTimeout() {
the test method itself as well as any set up or
tear down of the test fixture.
- @Repeat(10)
+ @Repeat(10)
@Test
public void testProcessRepeatedly() {
// ...
@@ -1033,7 +1048,7 @@ public class MyTest {
@RunWith(SpringJUnit4ClassRunner.class)
// ApplicationContext will be loaded from "/applicationContext.xml" and "/applicationContext-test.xml"// in the root of the classpath
-@ContextConfiguration(locations={"/applicationContext.xml", "/applicationContext-test.xml"})
+@ContextConfiguration({"/applicationContext.xml", "/applicationContext-test.xml"})
public class MyTest {
// class body...
}
@@ -1180,8 +1195,9 @@ public class HibernateTitleRepositoryTests {
private HibernateTitleRepository titleRepository;
@Test
- public void loadTitle() {
- Title title = titleRepository.loadTitle(new Long(10));
+ @Transactional
+ public void findById() {
+ Title title = titleRepository.findById(new Long(10));
assertNotNull(title);
}
}
@@ -1205,8 +1221,9 @@ public class HibernateTitleRepositoryTests {
}
@Test
- public void loadTitle() {
- Title title = titleRepository.loadTitle(new Long(10));
+ @Transactional
+ public void findById() {
+ Title title = titleRepository.findById(new Long(10));
assertNotNull(title);
}
}
@@ -1251,7 +1268,7 @@ public class HibernateTitleRepositoryTests {
@Autowired
@Override
public void setDataSource(@Qualifier("myDataSource") DataSource dataSource) {
- super.setDataSource(dataSource);
+ super.setDataSource(dataSource);
}
// ...