KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > smartValueObject > tools > TestSmartifier


1 package org.bsf.smartValueObject.tools;
2
3 import junit.framework.TestCase;
4
5 import java.util.Collection JavaDoc;
6
7 import org.bsf.smartValueObject.demo.SubsidiaryVO;
8 import org.bsf.smartValueObject.demo.CompanyVO;
9 import org.bsf.smartValueObject.Versionable;
10
11 /**
12  * Testcase for implementations of <code>Instrumentor</code> and
13  * <code>Versionable</code>.
14  *
15  * <ul>
16  * <li> is the generate bytecode valid ?</li>
17  * <li> are the interfaces correctly implemented ?</li>
18  * </ul>
19  *
20  * @see org.bsf.smartValueObject.tools.Instrumentor
21  * @see org.bsf.smartValueObject.Versionable
22  */

23 public class TestSmartifier extends TestCase {
24
25     // TODO: self containedness ?
26
public void setUp() {
27     }
28
29     public void testInstantiation() {
30        SubsidiaryVO subVO = new SubsidiaryVO();
31        CompanyVO CompanyVO = new CompanyVO();
32     }
33
34     public void testVersionable() {
35        CompanyVO CompanyVO = new CompanyVO();
36         if (!(CompanyVO instanceof Versionable)) {
37             fail("CompanyVO doesn't implement Versionable");
38         }
39         SubsidiaryVO subVO = new SubsidiaryVO();
40         if (!(subVO instanceof Versionable)) {
41             fail("SubsidiaryVO doesn't implement Versionable");
42         }
43     }
44
45     public void testDelete() {
46         CompanyVO compVO = new CompanyVO();
47         Versionable v = (Versionable) compVO;
48         v.delete();
49
50         assertTrue("compVO is not marked as deleted", v.isDeleted());
51     }
52
53     public void testCreate() {
54         CompanyVO compVO = new CompanyVO();
55         Versionable v = (Versionable) compVO;
56
57         v.create();
58         assertTrue("compVO is not marked as created", v.isCreated());
59     }
60
61     public void testDirty() {
62         CompanyVO compVO = new CompanyVO();
63         compVO.setName("foo");
64
65         Versionable v = (Versionable) compVO;
66         v.markClean();
67         assertTrue("compVO is not clean", !v.isDirty());
68
69         compVO.setName("foo2");
70         assertTrue("compVO is not dirty", v.isDirty());
71
72         // set the same value again, object should stay clean
73
v.markClean();
74         compVO.setName("foo2");
75         assertTrue("compVO is not clean", !v.isDirty());
76
77         // another value
78
compVO.setName("foo3");
79         assertTrue("compVO is not dirty", v.isDirty());
80
81         // check primitives
82
compVO.setId(new Long JavaDoc(20));
83         v.markClean();
84         compVO.setId(new Long JavaDoc(20));
85         assertTrue("compVO is not clean", !v.isDirty());
86     }
87
88     public void testNull() {
89         CompanyVO compVO = new CompanyVO();
90         Versionable v = (Versionable) compVO;
91
92         compVO.setName(null);
93         v.markClean();
94         compVO.setName(null);
95         assertTrue("compVO is not clean", !v.isDirty());
96
97         compVO.setName("test");
98         assertTrue("compVO is not dirty", v.isDirty());
99     }
100
101     public void testAssignment() {
102         CompanyVO compVO = new CompanyVO();
103         compVO.setId(new Long JavaDoc(10));
104         assertEquals("could not set id", new Long JavaDoc(10), compVO.getId());
105         compVO.setName("test");
106         assertEquals("could not set name", "test", compVO.getName());
107     }
108
109     public void testCollections() {
110         CompanyVO compVO = new CompanyVO();
111         compVO.addSubsidiary(new SubsidiaryVO());
112         compVO.addSubsidiary(new SubsidiaryVO());
113         compVO.addSubsidiary(new SubsidiaryVO());
114
115         Collection JavaDoc c = compVO.getSubsidiaries();
116         assertTrue("collection doesn't implement versionable",
117                 c instanceof Versionable);
118     }
119 }
120
Popular Tags