001    package org.springframework.beans;
002    
003    import junit.framework.Assert;
004    
005    import org.junit.Test;
006    
007    public class BeanUtilsTest {
008    
009            public class A {
010                    String foo;
011                    String bar;
012    
013                    public String getFoo() {
014                            return foo;
015                    }
016    
017                    public void setFoo(String foo) {
018                            this.foo = foo;
019                    }
020    
021                    public String getBar() {
022                            return bar;
023                    }
024    
025                    public void setBar(String bar) {
026                            this.bar = bar;
027                    }
028            }
029    
030            public class B {
031                    String foo;
032                    String bar;
033    
034                    public String getFoo() {
035                            return foo;
036                    }
037    
038                    public void setFoo(String foo) {
039                            this.foo = foo;
040                    }
041    
042                    public String getBar() {
043                            return bar;
044                    }
045    
046                    public void setBar(String bar) {
047                            this.bar = bar;
048                    }
049            }
050    
051            @Test
052            public void copyProperties() {
053                    A a = new A();
054                    a.setFoo("foo");
055                    a.setBar("bar");
056    
057                    B b = new B();
058    
059                    BeanUtils.copyProperties(a, b);
060                    Assert.assertEquals(b.getFoo(), a.getFoo());
061                    Assert.assertEquals(b.getBar(), b.getBar());
062                    
063                    a.setFoo(null);
064                    b.setFoo("foo-times-2");
065                    
066                    BeanUtils.copyProperties(a, b);
067                    System.out.println(b.getFoo());
068    
069            }
070    
071    }