1 package org.apache.commons.beanutils2;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.commons.beanutils2.BeanUtils.on;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25
26 import org.apache.commons.beanutils2.testbeans.TestBean;
27 import org.apache.commons.beanutils2.testbeans.ThrowingExceptionBean;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 public final class GetPropertyTestCase
33 {
34
35 private TestBean bean;
36 private ThrowingExceptionBean exceptionBean;
37
38 @Before
39 public void setUp()
40 {
41 bean = new TestBean();
42 exceptionBean = new ThrowingExceptionBean();
43 }
44
45 @After
46 public void tearDown()
47 {
48 bean = null;
49 exceptionBean = null;
50 }
51
52
53
54
55 @Test
56 public void getSimpleBoolean()
57 throws Exception
58 {
59 Object value = on( bean ).get( "booleanProperty" ).get();
60 assertNotNull( "Got no value", value );
61 assertTrue( "Got a value of the wrong type", ( value instanceof Boolean ) );
62 assertTrue( "Got an incorrect value", ( (Boolean) value ).booleanValue() == bean.getBooleanProperty() );
63 }
64
65 @Test( expected = PropertyNotReadableException.class )
66 public void getWirteOnlyProperty()
67 throws Exception
68 {
69 on( bean ).get( "writeOnlyProperty" );
70 }
71
72 @Test( expected = NoSuchPropertyException.class )
73 public void getUnknownProperty()
74 throws Exception
75 {
76 on( bean ).get( "unknown" );
77 }
78
79 @Test( expected = NullPointerException.class )
80 public void getNull()
81 throws Exception
82 {
83 on( bean ).get( null );
84 }
85
86 @Test( expected = NoSuchPropertyException.class )
87 public void getPrivateProperty()
88 {
89 on( exceptionBean ).get( "privateProperty" );
90 }
91
92 @Test( expected = NoSuchPropertyException.class )
93 public void getProtectedProperty()
94 {
95 on( exceptionBean ).get( "protectedProperty" );
96 }
97
98 @Test( expected = NoSuchPropertyException.class )
99 public void getDefaultProperty()
100 {
101 on( exceptionBean ).get( "defaultProperty" );
102 }
103
104 @Test( expected = PropertyGetterInvocationException.class )
105 public void getExcpetionProperty()
106 {
107 on( exceptionBean ).get( "exceptionProperty" );
108 }
109
110 }