01: package org.conform;
02:
03: import junit.framework.TestCase;
04:
05: import java.util.List;
06: import java.lang.reflect.ParameterizedType;
07:
08: import org.apache.commons.lang.builder.EqualsBuilder;
09:
10: public class MetaTest extends TestCase {
11:
12: Beans beans = new Beans();
13:
14: protected void setUp() throws Exception {
15: beans.addBeanMeta(new BeanMeta(Person.class));
16: beans.addBeanMeta(new BeanMeta(Address.class));
17: }
18:
19: public void testBasics() throws Exception {
20: BeanMeta personBeanMeta = beans.getBeanMeta(Person.class);
21: assertEquals(Person.class, personBeanMeta.getType());
22: assertEquals(3, personBeanMeta.getProperties().length);
23:
24: PropertyMeta addressesPropertyMeta = personBeanMeta
25: .getProperty("addresses");
26: assertEquals(List.class, addressesPropertyMeta.getType());
27: System.out.println(((ParameterizedType) Person.class.getMethod(
28: "getAddresses").getGenericReturnType())
29: .getActualTypeArguments()[0]);
30: }
31:
32: public void testClone() throws Exception {
33: BeanMeta personBeanMeta = beans.getBeanMeta(Person.class);
34: BeanMeta clonedBeanMeta = (BeanMeta) personBeanMeta.clone();
35: assertEquals(personBeanMeta, clonedBeanMeta);
36: assertEquals(Person.class, clonedBeanMeta.getType());
37: assertEquals(3, clonedBeanMeta.getProperties().length);
38:
39: for (int i = 0; i < personBeanMeta.getProperties().length; i++) {
40: PropertyMeta personPropertyMeta = personBeanMeta
41: .getProperties()[i];
42: PropertyMeta clonedPropertyMeta = clonedBeanMeta
43: .getProperties()[i];
44: assertEquals(personPropertyMeta, clonedPropertyMeta);
45: assertTrue(EqualsBuilder.reflectionEquals(
46: personPropertyMeta, clonedPropertyMeta));
47: }
48: assertTrue(EqualsBuilder.reflectionEquals(personBeanMeta,
49: clonedBeanMeta));
50: }
51: }
|