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