KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > introspector > IntrospectorTest


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.introspector;
4
5 import junit.framework.TestCase;
6 import jodd.introspector.test.Abean;
7 import jodd.introspector.test.Bbean;
8 import jodd.introspector.test.Ac;
9 import jodd.introspector.test.Bc;
10
11 import java.lang.reflect.Method JavaDoc;
12 import java.lang.reflect.Constructor JavaDoc;
13
14 public class IntrospectorTest extends TestCase {
15
16     public void testBasic() {
17         ClassDescriptor cd = DefaultIntrospector.lookup(Abean.class);
18         assertNotNull(cd);
19         Method JavaDoc[] getters = cd.getAllBeanGetters();
20         assertEquals(2, getters.length);
21         assertNotNull(cd.getBeanGetter("fooProp"));
22         assertNotNull(cd.getBeanGetter("something"));
23         assertNull(cd.getBeanGetter("FooProp"));
24         assertNull(cd.getBeanGetter("Something"));
25         assertNull(cd.getBeanGetter("notExisting"));
26
27         Method JavaDoc[] setters = cd.getAllBeanSetters();
28         assertEquals(1, setters.length);
29     }
30
31     public void testExtends() {
32         ClassDescriptor cd = DefaultIntrospector.lookup(Bbean.class);
33         assertNotNull(cd);
34
35         Method JavaDoc[] getters = cd.getAllBeanGetters();
36         assertEquals(2, getters.length);
37         getters = cd.getAllBeanGetters(true);
38         assertEquals(3, getters.length);
39         assertNotNull(cd.getBeanGetter("fooProp"));
40         assertNotNull(cd.getBeanGetter("something"));
41         assertNull(cd.getBeanGetter("FooProp"));
42         assertNull(cd.getBeanGetter("Something"));
43         assertNull(cd.getBeanGetter("notExisting"));
44
45         assertNotNull(cd.getBeanGetter("boo", true));
46         assertNull(cd.getBeanGetter("boo"));
47
48         Method JavaDoc[] setters = cd.getAllBeanSetters();
49         assertEquals(1, setters.length);
50         setters = cd.getAllBeanSetters(true);
51         assertEquals(2, setters.length);
52     }
53
54     public void testCtors() {
55         ClassDescriptor cd = DefaultIntrospector.lookup(Ac.class);
56         Constructor JavaDoc[] ctors = cd.getAllCtors();
57         assertEquals(1, ctors.length);
58         ctors = cd.getAllCtors(true);
59         assertEquals(2, ctors.length);
60         assertNotNull(cd.getDefaultCtor(true));
61         assertNull(cd.getDefaultCtor());
62
63         Constructor JavaDoc ctor = cd.getCtor(new Class JavaDoc[]{Integer JavaDoc.class}, true);
64         assertNotNull(ctor);
65
66         cd = DefaultIntrospector.lookup(Bc.class);
67         ctors = cd.getAllCtors();
68         assertEquals(1, ctors.length);
69         ctors = cd.getAllCtors(true);
70         assertEquals(1, ctors.length);
71         assertNull(cd.getDefaultCtor());
72         assertNull(cd.getDefaultCtor(true));
73
74         ctor = cd.getCtor(new Class JavaDoc[]{Integer JavaDoc.class}, true);
75         assertNull(ctor);
76         ctor = cd.getCtor(new Class JavaDoc[]{String JavaDoc.class}, true);
77         assertNotNull(ctor);
78
79     }
80 }
81
Popular Tags