01: /*
02: * Copyright 2003 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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 {
29: BeanGenerator bg = new BeanGenerator();
30: bg.addProperty("sin", Double.TYPE);
31: Object bean = bg.create();
32:
33: PropertyDescriptor[] pds = ReflectUtils.getBeanProperties(bean
34: .getClass());
35: assertTrue(pds.length == 1);
36: assertTrue(pds[0].getName().equals("sin"));
37: assertTrue(pds[0].getPropertyType().equals(Double.TYPE));
38: }
39:
40: public void testSuperclass() throws Exception {
41: BeanGenerator bg = new BeanGenerator();
42: bg.setSuperclass(MA.class);
43: bg.addProperty("sin", Double.TYPE);
44: Object bean = bg.create();
45:
46: assertTrue(bean instanceof MA);
47: assertTrue(BeanMap.create(bean).keySet().contains("sin"));
48: }
49:
50: public TestBeanGenerator(String testName) {
51: super (testName);
52: }
53:
54: public static void main(String[] args) {
55: junit.textui.TestRunner.run(suite());
56: }
57:
58: public static Test suite() {
59: return new TestSuite(TestBeanGenerator.class);
60: }
61: }
|