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 net.sf.cglib.core.Converter;
19: import java.lang.reflect.Method;
20: import junit.framework.*;
21:
22: /**
23: *
24: * @author baliuka
25: */
26: public class TestBeanCopier extends TestCase {
27:
28: public void testSimple() {
29: BeanCopier copier = BeanCopier
30: .create(MA.class, MA.class, false);
31: MA bean1 = new MA();
32: bean1.setIntP(42);
33: MA bean2 = new MA();
34: copier.copy(bean1, bean2, null);
35: assertTrue(bean2.getIntP() == 42);
36: }
37:
38: public void testConvert() {
39: BeanCopier copier = BeanCopier.create(MA.class, MA.class, true);
40: MA bean1 = new MA();
41: bean1.setIntP(42);
42: MA bean2 = new MA();
43: copier.copy(bean1, bean2, new Converter() {
44: public Object convert(Object value, Class target,
45: Object context) {
46: if (target.equals(Integer.TYPE)) {
47: return new Integer(((Number) value).intValue() + 1);
48: }
49: return value;
50: }
51: });
52: assertTrue(bean2.getIntP() == 43);
53: }
54:
55: public TestBeanCopier(java.lang.String testName) {
56: super (testName);
57: }
58:
59: public static void main(java.lang.String[] args) {
60: junit.textui.TestRunner.run(suite());
61: }
62:
63: public static Test suite() {
64: return new TestSuite(TestBeanCopier.class);
65: }
66: }
|