reviewed Javadoc for abstract test classes

This commit is contained in:
Mic 2013-02-15 09:53:47 +08:00
parent 54a0186dd4
commit b2626bd509
6 changed files with 108 additions and 227 deletions

View file

@ -1,3 +1,18 @@
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -10,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.repository.OwnerRepository; import org.springframework.samples.petclinic.repository.OwnerRepository;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
@ -18,29 +32,10 @@ import org.springframework.transaction.annotation.Transactional;
* Base class for {@link OwnerRepository} integration tests. * Base class for {@link OwnerRepository} integration tests.
* </p> * </p>
* <p> * <p>
* &quot;AbstractClinicTests-context.xml&quot; declares a common * Subclasses should specify Spring context configuration using {@link ContextConfiguration @ContextConfiguration} annotation
* {@link javax.sql.DataSource DataSource}. Subclasses should specify
* additional context locations which declare a
* {@link org.springframework.transaction.PlatformTransactionManager PlatformTransactionManager}
* and a concrete implementation of {@link OwnerRepository}.
* </p> * </p>
* <p> * <p>
* This class extends {@link AbstractTransactionalJUnit4SpringContextTests}, * AbstractOwnerRepositoryTests and its subclasses benefit from the following services
* one of the valuable testing support classes provided by the
* <em>Spring TestContext Framework</em> found in the
* <code>org.springframework.test.context</code> package. The
* annotation-driven configuration used here represents best practice for
* integration tests with Spring. Note, however, that
* AbstractTransactionalJUnit4SpringContextTests serves only as a convenience
* for extension. For example, if you do not wish for your test classes to be
* tied to a Spring-specific class hierarchy, you may configure your tests with
* annotations such as {@link ContextConfiguration @ContextConfiguration},
* {@link org.springframework.test.context.TestExecutionListeners @TestExecutionListeners},
* {@link org.springframework.transaction.annotation.Transactional @Transactional},
* etc.
* </p>
* <p>
* AbstractClinicTests and its subclasses benefit from the following services
* provided by the Spring TestContext Framework: * provided by the Spring TestContext Framework:
* </p> * </p>
* <ul> * <ul>
@ -48,39 +43,22 @@ import org.springframework.transaction.annotation.Transactional;
* unnecessary set up time between test execution.</li> * unnecessary set up time between test execution.</li>
* <li><strong>Dependency Injection</strong> of test fixture instances, * <li><strong>Dependency Injection</strong> of test fixture instances,
* meaning that we don't need to perform application context lookups. See the * meaning that we don't need to perform application context lookups. See the
* use of {@link Autowired @Autowired} on the <code>ownerRepository</code> instance * use of {@link Autowired @Autowired} on the <code>{@link AbstractOwnerRepositoryTests#ownerRepository ownerRepository}</code> instance
* variable, which uses autowiring <em>by type</em>. As an alternative, we * variable, which uses autowiring <em>by type</em>.
* could annotate <code>ownerRepository</code> with
* {@link javax.annotation.Resource @Resource} to achieve dependency injection
* <em>by name</em>.
* <em>(see: {@link ContextConfiguration @ContextConfiguration},
* {@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener DependencyInjectionTestExecutionListener})</em></li>
* <li><strong>Transaction management</strong>, meaning each test method is * <li><strong>Transaction management</strong>, meaning each test method is
* executed in its own transaction, which is automatically rolled back by * executed in its own transaction, which is automatically rolled back by
* default. Thus, even if tests insert or otherwise change database state, there * default. Thus, even if tests insert or otherwise change database state, there
* is no need for a teardown or cleanup script. * is no need for a teardown or cleanup script.
* <em>(see: {@link org.springframework.test.context.transaction.TransactionConfiguration @TransactionConfiguration}, * <li> An {@link org.springframework.context.ApplicationContext ApplicationContext} is
* {@link org.springframework.transaction.annotation.Transactional @Transactional},
* {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener TransactionalTestExecutionListener})</em></li>
* <li><strong>Useful inherited protected fields</strong>, such as a
* {@link org.springframework.jdbc.core.simple.SimpleJdbcTemplate SimpleJdbcTemplate}
* that can be used to verify database state after test operations or to verify
* the results of queries performed by application code. An
* {@link org.springframework.context.ApplicationContext ApplicationContext} is
* also inherited and can be used for explicit bean lookup if necessary. * also inherited and can be used for explicit bean lookup if necessary.
* <em>(see: {@link org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests AbstractJUnit4SpringContextTests}, * </li>
* {@link AbstractTransactionalJUnit4SpringContextTests})</em></li>
* </ul> * </ul>
* <p>
* The Spring TestContext Framework and related unit and integration testing
* support classes are shipped in <code>spring-test.jar</code>.
* </p>
* *
* @author Ken Krebs * @author Ken Krebs
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
* * @author Michael Isvy * @author Michael Isvy
*/ */
public abstract class AbstractOwnerRepositoryTests { public abstract class AbstractOwnerRepositoryTests {

View file

@ -1,3 +1,18 @@
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -13,79 +28,21 @@ import org.springframework.samples.petclinic.model.Pet;
import org.springframework.samples.petclinic.model.PetType; import org.springframework.samples.petclinic.model.PetType;
import org.springframework.samples.petclinic.repository.OwnerRepository; import org.springframework.samples.petclinic.repository.OwnerRepository;
import org.springframework.samples.petclinic.repository.PetRepository; import org.springframework.samples.petclinic.repository.PetRepository;
import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.samples.petclinic.util.EntityUtils; import org.springframework.samples.petclinic.util.EntityUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* <p> * <p>
* Base class for {@link ClinicService} integration tests. * Base class for {@link OwnerRepository} integration tests.
* </p> * </p>
* <p> * <p>
* &quot;AbstractClinicTests-context.xml&quot; declares a common * see javadoc inside {@link AbstractOwnerRepositoryTests} for more details
* {@link javax.sql.DataSource DataSource}. Subclasses should specify
* additional context locations which declare a
* {@link org.springframework.transaction.PlatformTransactionManager PlatformTransactionManager}
* and a concrete implementation of {@link ClinicService}.
* </p>
* <p>
* This class extends {@link AbstractTransactionalJUnit4SpringContextTests},
* one of the valuable testing support classes provided by the
* <em>Spring TestContext Framework</em> found in the
* <code>org.springframework.test.context</code> package. The
* annotation-driven configuration used here represents best practice for
* integration tests with Spring. Note, however, that
* AbstractTransactionalJUnit4SpringContextTests serves only as a convenience
* for extension. For example, if you do not wish for your test classes to be
* tied to a Spring-specific class hierarchy, you may configure your tests with
* annotations such as {@link ContextConfiguration @ContextConfiguration},
* {@link org.springframework.test.context.TestExecutionListeners @TestExecutionListeners},
* {@link org.springframework.transaction.annotation.Transactional @Transactional},
* etc.
* </p>
* <p>
* AbstractClinicTests and its subclasses benefit from the following services
* provided by the Spring TestContext Framework:
* </p>
* <ul>
* <li><strong>Spring IoC container caching</strong> which spares us
* unnecessary set up time between test execution.</li>
* <li><strong>Dependency Injection</strong> of test fixture instances,
* meaning that we don't need to perform application context lookups. See the
* use of {@link Autowired @Autowired} on the <code>petRepository</code> instance
* variable, which uses autowiring <em>by type</em>. As an alternative, we
* could annotate <code>petRepository</code> with
* {@link javax.annotation.Resource @Resource} to achieve dependency injection
* <em>by name</em>.
* <em>(see: {@link ContextConfiguration @ContextConfiguration},
* {@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener DependencyInjectionTestExecutionListener})</em></li>
* <li><strong>Transaction management</strong>, meaning each test method is
* executed in its own transaction, which is automatically rolled back by
* default. Thus, even if tests insert or otherwise change database state, there
* is no need for a teardown or cleanup script.
* <em>(see: {@link org.springframework.test.context.transaction.TransactionConfiguration @TransactionConfiguration},
* {@link org.springframework.transaction.annotation.Transactional @Transactional},
* {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener TransactionalTestExecutionListener})</em></li>
* <li><strong>Useful inherited protected fields</strong>, such as a
* {@link org.springframework.jdbc.core.simple.SimpleJdbcTemplate SimpleJdbcTemplate}
* that can be used to verify database state after test operations or to verify
* the results of queries performed by application code. An
* {@link org.springframework.context.ApplicationContext ApplicationContext} is
* also inherited and can be used for explicit bean lookup if necessary.
* <em>(see: {@link org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests AbstractJUnit4SpringContextTests},
* {@link AbstractTransactionalJUnit4SpringContextTests})</em></li>
* </ul>
* <p>
* The Spring TestContext Framework and related unit and integration testing
* support classes are shipped in <code>spring-test.jar</code>.
* </p>
* *
* @author Ken Krebs * @author Ken Krebs
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
* @author Michael Isvy
*/ */
public abstract class AbstractPetRepositoryTests { public abstract class AbstractPetRepositoryTests {

View file

@ -1,3 +1,18 @@
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -7,80 +22,23 @@ import java.util.Collection;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Vet; import org.springframework.samples.petclinic.model.Vet;
import org.springframework.samples.petclinic.repository.OwnerRepository;
import org.springframework.samples.petclinic.repository.VetRepository; import org.springframework.samples.petclinic.repository.VetRepository;
import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.samples.petclinic.util.EntityUtils; import org.springframework.samples.petclinic.util.EntityUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* <p> * <p>
* Base class for {@link ClinicService} integration tests. * Base class for {@link OwnerRepository} integration tests.
* </p> * </p>
* <p> * <p>
* &quot;AbstractClinicTests-context.xml&quot; declares a common * see javadoc inside {@link AbstractVetRepositoryTests} for more details
* {@link javax.sql.DataSource DataSource}. Subclasses should specify
* additional context locations which declare a
* {@link org.springframework.transaction.PlatformTransactionManager PlatformTransactionManager}
* and a concrete implementation of {@link ClinicService}.
* </p>
* <p>
* This class extends {@link AbstractTransactionalJUnit4SpringContextTests},
* one of the valuable testing support classes provided by the
* <em>Spring TestContext Framework</em> found in the
* <code>org.springframework.test.context</code> package. The
* annotation-driven configuration used here represents best practice for
* integration tests with Spring. Note, however, that
* AbstractTransactionalJUnit4SpringContextTests serves only as a convenience
* for extension. For example, if you do not wish for your test classes to be
* tied to a Spring-specific class hierarchy, you may configure your tests with
* annotations such as {@link ContextConfiguration @ContextConfiguration},
* {@link org.springframework.test.context.TestExecutionListeners @TestExecutionListeners},
* {@link org.springframework.transaction.annotation.Transactional @Transactional},
* etc.
* </p>
* <p>
* AbstractClinicTests and its subclasses benefit from the following services
* provided by the Spring TestContext Framework:
* </p>
* <ul>
* <li><strong>Spring IoC container caching</strong> which spares us
* unnecessary set up time between test execution.</li>
* <li><strong>Dependency Injection</strong> of test fixture instances,
* meaning that we don't need to perform application context lookups. See the
* use of {@link Autowired @Autowired} on the <code>petRepository</code> instance
* variable, which uses autowiring <em>by type</em>. As an alternative, we
* could annotate <code>petRepository</code> with
* {@link javax.annotation.Resource @Resource} to achieve dependency injection
* <em>by name</em>.
* <em>(see: {@link ContextConfiguration @ContextConfiguration},
* {@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener DependencyInjectionTestExecutionListener})</em></li>
* <li><strong>Transaction management</strong>, meaning each test method is
* executed in its own transaction, which is automatically rolled back by
* default. Thus, even if tests insert or otherwise change database state, there
* is no need for a teardown or cleanup script.
* <em>(see: {@link org.springframework.test.context.transaction.TransactionConfiguration @TransactionConfiguration},
* {@link org.springframework.transaction.annotation.Transactional @Transactional},
* {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener TransactionalTestExecutionListener})</em></li>
* <li><strong>Useful inherited protected fields</strong>, such as a
* {@link org.springframework.jdbc.core.simple.SimpleJdbcTemplate SimpleJdbcTemplate}
* that can be used to verify database state after test operations or to verify
* the results of queries performed by application code. An
* {@link org.springframework.context.ApplicationContext ApplicationContext} is
* also inherited and can be used for explicit bean lookup if necessary.
* <em>(see: {@link org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests AbstractJUnit4SpringContextTests},
* {@link AbstractTransactionalJUnit4SpringContextTests})</em></li>
* </ul>
* <p>
* The Spring TestContext Framework and related unit and integration testing
* support classes are shipped in <code>spring-test.jar</code>.
* </p>
* *
* @author Ken Krebs * @author Ken Krebs
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
* @author Michael Isvy
*/ */
public abstract class AbstractVetRepositoryTests { public abstract class AbstractVetRepositoryTests {

View file

@ -1,3 +1,18 @@
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -6,80 +21,23 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Pet; import org.springframework.samples.petclinic.model.Pet;
import org.springframework.samples.petclinic.model.Visit; import org.springframework.samples.petclinic.model.Visit;
import org.springframework.samples.petclinic.repository.OwnerRepository;
import org.springframework.samples.petclinic.repository.PetRepository; import org.springframework.samples.petclinic.repository.PetRepository;
import org.springframework.samples.petclinic.repository.VisitRepository; import org.springframework.samples.petclinic.repository.VisitRepository;
import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* <p> * <p>
* Base class for {@link ClinicService} integration tests. * Base class for {@link OwnerRepository} integration tests.
* </p> * </p>
* <p> * <p>
* &quot;AbstractClinicTests-context.xml&quot; declares a common * see javadoc inside {@link AbstractVetRepositoryTests} for more details
* {@link javax.sql.DataSource DataSource}. Subclasses should specify
* additional context locations which declare a
* {@link org.springframework.transaction.PlatformTransactionManager PlatformTransactionManager}
* and a concrete implementation of {@link ClinicService}.
* </p>
* <p>
* This class extends {@link AbstractTransactionalJUnit4SpringContextTests},
* one of the valuable testing support classes provided by the
* <em>Spring TestContext Framework</em> found in the
* <code>org.springframework.test.context</code> package. The
* annotation-driven configuration used here represents best practice for
* integration tests with Spring. Note, however, that
* AbstractTransactionalJUnit4SpringContextTests serves only as a convenience
* for extension. For example, if you do not wish for your test classes to be
* tied to a Spring-specific class hierarchy, you may configure your tests with
* annotations such as {@link ContextConfiguration @ContextConfiguration},
* {@link org.springframework.test.context.TestExecutionListeners @TestExecutionListeners},
* {@link org.springframework.transaction.annotation.Transactional @Transactional},
* etc.
* </p>
* <p>
* AbstractClinicTests and its subclasses benefit from the following services
* provided by the Spring TestContext Framework:
* </p>
* <ul>
* <li><strong>Spring IoC container caching</strong> which spares us
* unnecessary set up time between test execution.</li>
* <li><strong>Dependency Injection</strong> of test fixture instances,
* meaning that we don't need to perform application context lookups. See the
* use of {@link Autowired @Autowired} on the <code>petRepository</code> instance
* variable, which uses autowiring <em>by type</em>. As an alternative, we
* could annotate <code>petRepository</code> with
* {@link javax.annotation.Resource @Resource} to achieve dependency injection
* <em>by name</em>.
* <em>(see: {@link ContextConfiguration @ContextConfiguration},
* {@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener DependencyInjectionTestExecutionListener})</em></li>
* <li><strong>Transaction management</strong>, meaning each test method is
* executed in its own transaction, which is automatically rolled back by
* default. Thus, even if tests insert or otherwise change database state, there
* is no need for a teardown or cleanup script.
* <em>(see: {@link org.springframework.test.context.transaction.TransactionConfiguration @TransactionConfiguration},
* {@link org.springframework.transaction.annotation.Transactional @Transactional},
* {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener TransactionalTestExecutionListener})</em></li>
* <li><strong>Useful inherited protected fields</strong>, such as a
* {@link org.springframework.jdbc.core.simple.SimpleJdbcTemplate SimpleJdbcTemplate}
* that can be used to verify database state after test operations or to verify
* the results of queries performed by application code. An
* {@link org.springframework.context.ApplicationContext ApplicationContext} is
* also inherited and can be used for explicit bean lookup if necessary.
* <em>(see: {@link org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests AbstractJUnit4SpringContextTests},
* {@link AbstractTransactionalJUnit4SpringContextTests})</em></li>
* </ul>
* <p>
* The Spring TestContext Framework and related unit and integration testing
* support classes are shipped in <code>spring-test.jar</code>.
* </p>
* *
* @author Ken Krebs * @author Ken Krebs
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
* @author Michael Isvy
*/ */
public abstract class AbstractVisitRepositoryTests { public abstract class AbstractVisitRepositoryTests {

View file

@ -1,3 +1,18 @@
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View file

@ -1,3 +1,18 @@
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic.jdbc; package org.springframework.samples.petclinic.jdbc;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;