From c7661d53412249a428c8765dcb23b5c7550aa37b Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 29 Jul 2009 15:51:18 +0000 Subject: [PATCH] [SPR-5781] Added a "note" for static import for assertions; additional polishing. --- spring-framework-reference/src/testing.xml | 60 +++++++++++++++------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/spring-framework-reference/src/testing.xml b/spring-framework-reference/src/testing.xml index d2fbaa087e4..fd73679e4ab 100644 --- a/spring-framework-reference/src/testing.xml +++ b/spring-framework-reference/src/testing.xml @@ -179,7 +179,7 @@ linkend="testcontext-framework">Spring TestContext Framework. The TestContext Framework is agnostic of the actual testing framework in use, thus allowing instrumentation of tests in various environments - including JUnit 3.8, JUnit 4.6, TestNG, etc. + including JUnit, TestNG, etc. Legacy JUnit 3.8 class hierarchy is deprecated @@ -811,17 +811,17 @@ public void testProcessRepeatedly() { The Spring TestContext Framework (located in the org.springframework.test.context package) provides - generic, annotation-driven unit and integration testing support that is - agnostic of the testing framework in use, for example JUnit 3.8, JUnit - 4.6, TestNG 5.8, etc. The TestContext framework also places a great deal - of importance on convention over configuration with - reasonable defaults that can be overridden via annotation-based - configuration. + generic, annotation-driven unit and integration testing support that + is agnostic of the testing framework in use, for example JUnit 3.8, + JUnit 4.6, TestNG 5.9, etc. The TestContext framework also places a + great deal of importance on convention over + configuration with reasonable defaults that can be + overridden via annotation-based configuration. In addition to generic testing infrastructure, the TestContext - framework provides explicit support for JUnit 3.8, JUnit 4.6, and TestNG - 5.8 in the form of abstract support classes. For - JUnit 4.6, the framework also provides a custom + framework provides explicit support for JUnit 3.8, JUnit 4.6, and + TestNG 5.9 in the form of abstract support + classes. For JUnit 4.6, the framework also provides a custom Runner which allows one to write test classes that are not required to extend a particular class hierarchy. @@ -1120,6 +1120,17 @@ public class ExtendedTest extends BaseTest { The same DI techniques can be used in conjunction with any testing framework. + + Static imports for assertions + The following examples make calls to static + assertion methods such as assertNotNull() + but without prepending the call with + "Assert.". In such cases you should assume + that the method has been properly imported via + an import static declaration which is + simply not shown in the example. + + @RunWith(SpringJUnit4ClassRunner.class) // specifies the Spring configuration to load for this test fixture @ContextConfiguration("daos.xml") @@ -1241,12 +1252,15 @@ public final class HibernateTitleDaoTests { @Qualifier annotation to indicate a specific target bean as follows: - ... - @Override @Autowired + // ... + + @Autowired + @Override public void setDataSource(@Qualifier("myDataSource") DataSource dataSource) { super.setDataSource(dataSource); } -... + +// ... The specified qualifier value indicates the specific DataSource bean to inject, narrowing @@ -1267,12 +1281,15 @@ public final class HibernateTitleDaoTests { bean with that specific name, no matter whether there is one or more beans of the given type. - ... - @Override @Resource("myDataSource") + // ... + + @Resource("myDataSource") + @Override public void setDataSource(DataSource dataSource) { super.setDataSource(dataSource); } -... + +// ... @@ -1411,7 +1428,8 @@ public class FictitiousTransactionalTest { and one which correctly exposes the results of flushing the session. - ... + // ... + @Autowired private SessionFactory sessionFactory; @@ -1428,7 +1446,8 @@ public void updateWithSessionFlush() { // Manual flush is required to avoid false positive in test sessionFactory.getCurrentSession().flush(); } -... + +// ... @@ -1719,7 +1738,10 @@ public class SimpleTest { AbstractClinicTests, for which a partial listing is shown below: - @ContextConfiguration + import static org.junit.Assert.assertEquals; +// import ... + +@ContextConfiguration public abstract class AbstractClinicTests extends AbstractTransactionalJUnit4SpringContextTests { @Autowired