1 package org.apache.commons.beanutils2.testbeans;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import static org.junit.Assert.assertArrayEquals;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertSame;
23
24 public final class TestBeanUtils
25 {
26 private TestBeanUtils()
27 {
28
29 }
30
31 public static void changeArrayProperties( TestBean testBean )
32 {
33 int intArray[] = new int[] { 123, 456, 789 };
34 String stringArray[] = new String[] { "New String 0", "New String 1" };
35 testBean.setIntArray( intArray );
36 testBean.setStringArray( stringArray );
37 }
38
39 public static void changeScalarProperties( TestBean testBean )
40 {
41 testBean.setBooleanProperty( false );
42
43 testBean.setByteProperty( (byte) 111 );
44 testBean.setDoubleProperty( 432.0 );
45
46 testBean.setIntProperty( 543 );
47 testBean.setLongProperty( 123456789l );
48 testBean.setNullProperty( "Non-null value" );
49 testBean.setShortProperty( (short) 654 );
50
51 }
52
53
54
55
56
57
58
59
60 public static void assertReadWritePropertiesEquals( TestBean expected, TestBean actual )
61 {
62 assertEquals( "Property 'anotherNested' is not equal!", expected.getAnotherNested(), actual.getAnotherNested() );
63 assertEquals( "Property 'booleanProperty' is not equal!", expected.getBooleanProperty(),
64 actual.getBooleanProperty() );
65 assertEquals( "Property 'booleanSecond' is not equal!", expected.isBooleanSecond(), actual.isBooleanSecond() );
66 assertEquals( "Property 'byteProperty' is not equal!", expected.getByteProperty(), actual.getByteProperty() );
67 assertArrayEquals( "Property 'DateArrayProperty' is not equal!", expected.getDateArrayProperty(),
68 actual.getDateArrayProperty() );
69 assertEquals( "Property 'dateProperty' is not equal!", expected.getDateProperty(), actual.getDateProperty() );
70 assertEquals( "Property 'doubleProperty' is not equal!", expected.getDoubleProperty(),
71 actual.getDoubleProperty(), 0.0 );
72 assertArrayEquals( "Property 'dupProperty' is not equal!", expected.getDupProperty(), actual.getDupProperty() );
73 assertEquals( "Property 'floatProperty' is not equal!", expected.getFloatProperty(), actual.getFloatProperty(),
74 0.0 );
75 assertArrayEquals( "Property 'intArrayProperty' is not equal!", expected.getIntArray(), actual.getIntArray() );
76 assertEquals( "Property 'intProperty' is not equal!", expected.getIntProperty(), actual.getIntProperty() );
77 assertEquals( "Property 'invalidBoolean' is not equal!", expected.getInvalidBoolean(),
78 actual.getInvalidBoolean() );
79 assertEquals( "Property 'listIndexed' is not equal!", expected.getListIndexed(), actual.getListIndexed() );
80 assertEquals( "Property 'longProperty' is not equal!", expected.getLongProperty(), actual.getLongProperty() );
81 assertEquals( "Property 'mapProperty' is not equal!", expected.getMapProperty(), actual.getMapProperty() );
82 assertEquals( "Property 'nested' is not equal!", expected.getNested(), actual.getNested() );
83 assertEquals( "Property 'nullProperty' is not equal!", expected.getNullProperty(), actual.getNullProperty() );
84 assertEquals( "Property 'shortProperty' is not equal!", expected.getShortProperty(), actual.getShortProperty() );
85 assertArrayEquals( "Property 'stringArray' is not equal!", expected.getStringArray(), actual.getStringArray() );
86 assertEquals( "Property 'stringProperty' is not equal!", expected.getStringProperty(),
87 actual.getStringProperty() );
88 }
89
90
91
92
93
94 public static void assertShallow( TestBean referenced, TestBean referencing )
95 {
96 assertSame( referenced.getAnotherNested(), referencing.getAnotherNested() );
97 assertSame( referenced.getDateArrayProperty(), referencing.getDateArrayProperty() );
98 assertSame( referenced.getDateProperty(), referencing.getDateProperty() );
99 assertSame( referenced.getDateProperty(), referencing.getDateProperty() );
100 assertSame( referenced.getDupProperty(), referencing.getDupProperty() );
101 assertSame( referenced.getIntArray(), referencing.getIntArray() );
102 assertSame( referenced.getMapProperty(), referencing.getMapProperty() );
103
104
105
106
107 assertSame( referenced.getStringArray(), referencing.getStringArray() );
108 assertSame( referenced.getStringProperty(), referencing.getStringProperty() );
109 }
110
111 }