Won't fix as I don't feel it's necessary to write JUnit tests for model objects. If users feel it's necessary, hopefully they can use the instructions/patches in this issue to assist them.
> Model Classes are missing testcases
> -----------------------------------
>
> Key: APF-365
> URL:
http://issues.appfuse.org/browse/APF-365> Project: AppFuse
> Issue Type: Improvement
> Components: Build, Test, or Deploy Process, Documentation, Persistence Layer
> Affects Versions: 1.9.1
> Environment: N/A
> Reporter: Christopher Barham
> Assignee: Matt Raible
> Priority: Minor
> Fix For: 1.9.5, 2.1
>
> Attachments: TestSpikes.zip, UserTest.java
>
>
> The model classes in /src/dao/**/model do not have corresponding tests. Although these are of the trivial getter/setter type, and the equals, hashcode, serializability - they have bitten me recently. Especially in the model where I inadvertantly add the generated ID into the equals method (against the advice of Hibernate gurus) and Id get lots of weird inequality conditions because I can't find a good composite key from the business data.
> So I thought I'd add in the tests using some handy tools:
> junit-addons from
http://junit-addons.sourceforge.net/> testutils from
http://gtcgroup.com/util/> 1) I add these to appfuse lib system in the usual way (mkdir, edit lib.properties, then change all test classpaths to include the new jars).
> 2) Then create a test/dao/**/model directory and for each model class I add a test such as:
> <code>
> package au.com.resolute.mongoose.model;
> import java.io.Serializable;
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
> import junitx.extensions.EqualsHashCodeTestCase;
> import junitx.extensions.SerializabilityTestCase;
> import com.gtcgroup.testutil.TestUtil;
> /**
> * $Id$
> *
> * @author Chris Barham
[hidden email]
> */
> public class UserTest extends TestCase {
> public static Test suite() {
> TestSuite suite = new TestSuite(UserTest.class);
> suite.addTestSuite(EqualsHashCodeTest.class);
> suite.addTestSuite(SerializabilityTest.class);
> return suite;
> }
> /**
> * Verify accessor methods
> */
> public void testAccessorsUser() {
> assertTrue(TestUtil.verifyMutable(new User()));
> }
> /**
> * <code>equals</code>/<code>hashCode</code> tests for the User class.
> */
> public static class EqualsHashCodeTest extends
> EqualsHashCodeTestCase {
> public EqualsHashCodeTest(String name) {
> super(name);
> }
> protected Object createInstance() {
> User a = new User();
> a.setUsername("ChrisBarham");
> return a;
> }
> protected Object createNotEqualInstance() {
> User b = new User();
> b.setUsername("FredBloggs");
> return b;
> }
> }
> /**
> * Serializability tests for the User class.
> */
> public static class SerializabilityTest extends
> SerializabilityTestCase {
> public SerializabilityTest(String name) {
> super(name);
> }
> protected Serializable createInstance() {
> User c = new User();
> c.setUsername("ChrisBarham");
> return c;
> }
> }
> }
> </code>
> It gets the code coverage up a bit higher too.
> Regards,
> Chris