KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > beans > TestBeanGenerator


1 /*
2  * Copyright 2003 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.cglib.beans;
17
18 import java.beans.*;
19 import java.lang.reflect.Method JavaDoc;
20 import junit.framework.*;
21 import net.sf.cglib.core.ReflectUtils;
22
23 /**
24  * @author Juozas Baliuka, Chris Nokleberg
25  */

26 public class TestBeanGenerator extends TestCase {
27     
28     public void testSimple() throws Exception JavaDoc {
29         BeanGenerator bg = new BeanGenerator();
30         bg.addProperty("sin", Double.TYPE);
31         Object JavaDoc bean = bg.create();
32         
33         PropertyDescriptor[] pds = ReflectUtils.getBeanProperties(bean.getClass());
34         assertTrue(pds.length == 1);
35         assertTrue(pds[0].getName().equals("sin"));
36         assertTrue(pds[0].getPropertyType().equals(Double.TYPE));
37     }
38
39     public void testSuperclass() throws Exception JavaDoc {
40         BeanGenerator bg = new BeanGenerator();
41         bg.setSuperclass(MA.class);
42         bg.addProperty("sin", Double.TYPE);
43         Object JavaDoc bean = bg.create();
44
45         assertTrue(bean instanceof MA);
46         assertTrue(BeanMap.create(bean).keySet().contains("sin"));
47     }
48
49     public TestBeanGenerator(String JavaDoc testName) {
50         super(testName);
51     }
52     
53     public static void main(String JavaDoc[] args) {
54         junit.textui.TestRunner.run(suite());
55     }
56     
57     public static Test suite() {
58         return new TestSuite(TestBeanGenerator.class);
59     }
60 }
61
Popular Tags