[SPR-5781] Added a "note" for static import for assertions; additional polishing.
This commit is contained in:
parent
5d009a2a98
commit
c7661d5341
|
|
@ -179,7 +179,7 @@
|
||||||
linkend="testcontext-framework">Spring TestContext Framework</link>. The
|
linkend="testcontext-framework">Spring TestContext Framework</link>. The
|
||||||
TestContext Framework is agnostic of the actual testing framework in
|
TestContext Framework is agnostic of the actual testing framework in
|
||||||
use, thus allowing instrumentation of tests in various environments
|
use, thus allowing instrumentation of tests in various environments
|
||||||
including JUnit 3.8, JUnit 4.6, TestNG, etc.</para>
|
including JUnit, TestNG, etc.</para>
|
||||||
|
|
||||||
<note>
|
<note>
|
||||||
<title>Legacy JUnit 3.8 class hierarchy is deprecated</title>
|
<title>Legacy JUnit 3.8 class hierarchy is deprecated</title>
|
||||||
|
|
@ -811,17 +811,17 @@ public void testProcessRepeatedly() {
|
||||||
<para>The <emphasis>Spring <classname>TestContext</classname>
|
<para>The <emphasis>Spring <classname>TestContext</classname>
|
||||||
Framework</emphasis> (located in the
|
Framework</emphasis> (located in the
|
||||||
<literal>org.springframework.test.context</literal> package) provides
|
<literal>org.springframework.test.context</literal> package) provides
|
||||||
generic, annotation-driven unit and integration testing support that is
|
generic, annotation-driven unit and integration testing support that
|
||||||
agnostic of the testing framework in use, for example JUnit 3.8, JUnit
|
is agnostic of the testing framework in use, for example JUnit 3.8,
|
||||||
4.6, TestNG 5.8, etc. The TestContext framework also places a great deal
|
JUnit 4.6, TestNG 5.9, etc. The TestContext framework also places a
|
||||||
of importance on <emphasis>convention over configuration</emphasis> with
|
great deal of importance on <emphasis>convention over
|
||||||
reasonable defaults that can be overridden via annotation-based
|
configuration</emphasis> with reasonable defaults that can be
|
||||||
configuration.</para>
|
overridden via annotation-based configuration.</para>
|
||||||
|
|
||||||
<para>In addition to generic testing infrastructure, the TestContext
|
<para>In addition to generic testing infrastructure, the TestContext
|
||||||
framework provides explicit support for JUnit 3.8, JUnit 4.6, and TestNG
|
framework provides explicit support for JUnit 3.8, JUnit 4.6, and
|
||||||
5.8 in the form of <literal>abstract</literal> support classes. For
|
TestNG 5.9 in the form of <literal>abstract</literal> support
|
||||||
JUnit 4.6, the framework also provides a custom
|
classes. For JUnit 4.6, the framework also provides a custom
|
||||||
<interfacename>Runner</interfacename> which allows one to write test
|
<interfacename>Runner</interfacename> which allows one to write test
|
||||||
classes that are not required to extend a particular class
|
classes that are not required to extend a particular class
|
||||||
hierarchy.</para>
|
hierarchy.</para>
|
||||||
|
|
@ -1120,6 +1120,17 @@ public class ExtendedTest extends BaseTest {
|
||||||
The same DI techniques can be used in conjunction with any testing
|
The same DI techniques can be used in conjunction with any testing
|
||||||
framework.</emphasis></para>
|
framework.</emphasis></para>
|
||||||
|
|
||||||
|
<note>
|
||||||
|
<title>Static imports for assertions</title>
|
||||||
|
<para>The following examples make calls to static
|
||||||
|
assertion methods such as <literal>assertNotNull()</literal>
|
||||||
|
but without prepending the call with
|
||||||
|
"<literal>Assert.</literal>". In such cases you should assume
|
||||||
|
that the method has been properly imported via
|
||||||
|
an <literal>import static</literal> declaration which is
|
||||||
|
simply not shown in the example.</para>
|
||||||
|
</note>
|
||||||
|
|
||||||
<programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
|
<programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
<lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation>
|
<lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation>
|
||||||
<emphasis role="bold">@ContextConfiguration("daos.xml")</emphasis>
|
<emphasis role="bold">@ContextConfiguration("daos.xml")</emphasis>
|
||||||
|
|
@ -1241,12 +1252,15 @@ public final class HibernateTitleDaoTests {
|
||||||
<interfacename>@Qualifier</interfacename> annotation to indicate a
|
<interfacename>@Qualifier</interfacename> annotation to indicate a
|
||||||
specific target bean as follows:</para>
|
specific target bean as follows:</para>
|
||||||
|
|
||||||
<programlisting language="java">...
|
<programlisting language="java"><lineannotation>// ...</lineannotation>
|
||||||
@Override @Autowired
|
|
||||||
|
@Autowired
|
||||||
|
@Override
|
||||||
public void setDataSource(<emphasis role="bold">@Qualifier("myDataSource")</emphasis> DataSource dataSource) {
|
public void setDataSource(<emphasis role="bold">@Qualifier("myDataSource")</emphasis> DataSource dataSource) {
|
||||||
super.setDataSource(dataSource);
|
super.setDataSource(dataSource);
|
||||||
}
|
}
|
||||||
...</programlisting>
|
|
||||||
|
<lineannotation>// ...</lineannotation></programlisting>
|
||||||
|
|
||||||
<para>The specified qualifier value indicates the specific
|
<para>The specified qualifier value indicates the specific
|
||||||
<interfacename>DataSource</interfacename> bean to inject, narrowing
|
<interfacename>DataSource</interfacename> 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
|
bean with that specific name, no matter whether there is one or more
|
||||||
beans of the given type.</para>
|
beans of the given type.</para>
|
||||||
|
|
||||||
<programlisting language="java">...
|
<programlisting language="java"><lineannotation>// ...</lineannotation>
|
||||||
@Override <emphasis role="bold">@Resource("myDataSource")</emphasis>
|
|
||||||
|
<emphasis role="bold">@Resource("myDataSource")</emphasis>
|
||||||
|
@Override
|
||||||
public void setDataSource(DataSource dataSource) {
|
public void setDataSource(DataSource dataSource) {
|
||||||
super.setDataSource(dataSource);
|
super.setDataSource(dataSource);
|
||||||
}
|
}
|
||||||
...</programlisting>
|
|
||||||
|
<lineannotation>// ...</lineannotation></programlisting>
|
||||||
</note>
|
</note>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
@ -1411,7 +1428,8 @@ public class FictitiousTransactionalTest {
|
||||||
and one which correctly exposes the results of flushing the
|
and one which correctly exposes the results of flushing the
|
||||||
session.</para>
|
session.</para>
|
||||||
|
|
||||||
<programlisting language="java">...
|
<programlisting language="java"><lineannotation>// ...</lineannotation>
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SessionFactory sessionFactory;
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
|
@ -1428,7 +1446,8 @@ public void updateWithSessionFlush() {
|
||||||
// Manual flush is required to avoid false positive in test
|
// Manual flush is required to avoid false positive in test
|
||||||
sessionFactory.getCurrentSession().flush();
|
sessionFactory.getCurrentSession().flush();
|
||||||
}
|
}
|
||||||
...</programlisting>
|
|
||||||
|
<lineannotation>// ...</lineannotation></programlisting>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -1719,7 +1738,10 @@ public class SimpleTest {
|
||||||
<classname>AbstractClinicTests</classname>, for which a partial listing
|
<classname>AbstractClinicTests</classname>, for which a partial listing
|
||||||
is shown below:</para>
|
is shown below:</para>
|
||||||
|
|
||||||
<programlisting language="java"><emphasis role="bold">@ContextConfiguration</emphasis>
|
<programlisting language="java">import static org.junit.Assert.assertEquals;
|
||||||
|
<lineannotation>// import ...</lineannotation>
|
||||||
|
|
||||||
|
<emphasis role="bold">@ContextConfiguration</emphasis>
|
||||||
public abstract class AbstractClinicTests <emphasis role="bold">extends AbstractTransactionalJUnit4SpringContextTests</emphasis> {
|
public abstract class AbstractClinicTests <emphasis role="bold">extends AbstractTransactionalJUnit4SpringContextTests</emphasis> {
|
||||||
|
|
||||||
<emphasis role="bold">@Autowired</emphasis>
|
<emphasis role="bold">@Autowired</emphasis>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue