1   /*
2    * BeanMappingPerfTest - Tests Java Bean to Java Bean mapping
3    * Copyright (C) 2007 Christian Schenk
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18   */
19  package org.christianschenk.beanmapping;
20  
21  import org.christianschenk.beanmapping.beans.A;
22  import org.christianschenk.beanmapping.beans.B;
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNull;
27  
28  public abstract class AbstractJavaBeanTest {
29  
30  	protected abstract void copy(A a1, A a2);
31  
32  	protected abstract void fillBiggerWithSmallerBean(B b, A a);
33  
34  	protected abstract void fillSmallerWithBiggerBean(A a, B b);
35  
36  	@Test
37  	public void copy() {
38  		final A a1 = new A(1, 2);
39  		final A a2 = new A();
40  		this.copy(a2, a1);
41  		assertEquals(a1.getI(), a2.getI());
42  		assertEquals(a1.getJ(), a2.getJ());
43  	}
44  
45  	@Test
46  	public void fillBiggerWithSmallerBean() {
47  		final A a = new A(1, 2);
48  		final B b = new B();
49  		this.fillBiggerWithSmallerBean(b, a);
50  		assertEquals(a.getI(), b.getI());
51  		assertEquals(a.getJ(), b.getJ());
52  		assertNull(b.getStr());
53  	}
54  
55  	@Test
56  	public void fillSmallerWithBiggerBean() {
57  		final A a = new A();
58  		final B b = new B(1, 2);
59  		this.fillSmallerWithBiggerBean(a, b);
60  		assertEquals(a.getI(), b.getI());
61  		assertEquals(a.getJ(), b.getJ());
62  		assertNull(b.getStr());
63  	}
64  }