View Javadoc

1   package org.springframework.beans;
2   
3   import junit.framework.Assert;
4   
5   import org.junit.Test;
6   
7   public class BeanUtilsTest {
8   
9   	public class A {
10  		String foo;
11  		String bar;
12  
13  		public String getFoo() {
14  			return foo;
15  		}
16  
17  		public void setFoo(String foo) {
18  			this.foo = foo;
19  		}
20  
21  		public String getBar() {
22  			return bar;
23  		}
24  
25  		public void setBar(String bar) {
26  			this.bar = bar;
27  		}
28  	}
29  
30  	public class B {
31  		String foo;
32  		String bar;
33  
34  		public String getFoo() {
35  			return foo;
36  		}
37  
38  		public void setFoo(String foo) {
39  			this.foo = foo;
40  		}
41  
42  		public String getBar() {
43  			return bar;
44  		}
45  
46  		public void setBar(String bar) {
47  			this.bar = bar;
48  		}
49  	}
50  
51  	@Test
52  	public void copyProperties() {
53  		A a = new A();
54  		a.setFoo("foo");
55  		a.setBar("bar");
56  
57  		B b = new B();
58  
59  		BeanUtils.copyProperties(a, b);
60  		Assert.assertEquals(b.getFoo(), a.getFoo());
61  		Assert.assertEquals(b.getBar(), b.getBar());
62  		
63  		a.setFoo(null);
64  		b.setFoo("foo-times-2");
65  		
66  		BeanUtils.copyProperties(a, b);
67  		System.out.println(b.getFoo());
68  
69  	}
70  
71  }