01: package org.araneaframework.tests;
02:
03: import java.util.List;
04: import junit.framework.TestCase;
05: import org.araneaframework.backend.util.BeanMapper;
06:
07: /**
08: * @author Taimo Peelo (taimo@araneaframework.org)
09: */
10: public class BeanMapperTest extends TestCase {
11: public static final Integer IA = new Integer(6);
12: public static final Integer IB = new Integer(8);
13:
14: public static class A {
15: private Integer a = IA;
16:
17: public Integer getA() {
18: return a;
19: }
20:
21: public void setA(Integer a) {
22: this .a = a;
23: }
24: }
25:
26: public static class B extends A {
27: private Integer b = IB;
28: private boolean t = true;
29:
30: public Integer getB() {
31: return b;
32: }
33:
34: public void setB(Integer b) {
35: this .b = b;
36: }
37:
38: public boolean isT() {
39: return t;
40: }
41:
42: public void setT(boolean t) {
43: this .t = t;
44: }
45: }
46:
47: public void testClassField() {
48: BeanMapper beanMapper = new BeanMapper(A.class);
49: A a = new A();
50: Object o = beanMapper.getFieldValue(a, "a");
51:
52: assertEquals(o, IA);
53: }
54:
55: public void testClassAndSuperClassFields() {
56: BeanMapper beanMapper = new BeanMapper(B.class);
57: B b = new B();
58:
59: assertEquals(beanMapper.getFieldValue(b, "a"), IA);
60: assertEquals(beanMapper.getFieldValue(b, "b"), IB);
61: assertEquals(beanMapper.getFieldValue(b, "t"), Boolean.TRUE);
62: }
63:
64: public void testGetFields() {
65: BeanMapper beanMapper = new BeanMapper(B.class);
66:
67: List beanFields = beanMapper.getFields();
68: assertTrue(beanFields.contains("a"));
69: assertTrue(beanFields.contains("b"));
70: assertTrue(beanFields.contains("t"));
71: }
72:
73: public void testGetFieldType() {
74: BeanMapper beanMapper = new BeanMapper(B.class);
75:
76: assertTrue(Integer.class.equals(beanMapper.getFieldType("a")));
77: assertTrue(Integer.class.equals(beanMapper.getFieldType("b")));
78: assertTrue(boolean.class.equals(beanMapper.getFieldType("t")));
79: }
80: }
|