01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.introspector;
04:
05: import junit.framework.TestCase;
06: import jodd.introspector.test.Abean;
07: import jodd.introspector.test.Bbean;
08: import jodd.introspector.test.Ac;
09: import jodd.introspector.test.Bc;
10:
11: import java.lang.reflect.Method;
12: import java.lang.reflect.Constructor;
13:
14: public class IntrospectorTest extends TestCase {
15:
16: public void testBasic() {
17: ClassDescriptor cd = DefaultIntrospector.lookup(Abean.class);
18: assertNotNull(cd);
19: Method[] 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[] 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[] 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[] 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[] 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 ctor = cd.getCtor(new Class[] { Integer.class },
64: true);
65: assertNotNull(ctor);
66:
67: cd = DefaultIntrospector.lookup(Bc.class);
68: ctors = cd.getAllCtors();
69: assertEquals(1, ctors.length);
70: ctors = cd.getAllCtors(true);
71: assertEquals(1, ctors.length);
72: assertNull(cd.getDefaultCtor());
73: assertNull(cd.getDefaultCtor(true));
74:
75: ctor = cd.getCtor(new Class[] { Integer.class }, true);
76: assertNull(ctor);
77: ctor = cd.getCtor(new Class[] { String.class }, true);
78: assertNotNull(ctor);
79:
80: }
81: }
|