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 import static org.apache.commons.beanutils2.BeanUtils.on;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23
24 import org.apache.commons.beanutils2.testbeans.TestBean;
25 import org.apache.commons.beanutils2.testbeans.ThrowingExceptionBean;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29
30 public class GetIndexedPropertyTestCase
31 {
32
33 private TestBean testBean;
34
35 private ThrowingExceptionBean exceptionBean;
36
37 @Before
38 public void setUp()
39 {
40 testBean = new TestBean();
41 exceptionBean = new ThrowingExceptionBean();
42 }
43
44 @After
45 public void tearDown()
46 {
47 testBean = null;
48 exceptionBean = null;
49 }
50
51 @Test( expected = NullPointerException.class )
52 public void getIndexedNull()
53 {
54 on( testBean ).getIndexed( null );
55 }
56
57 @Test( expected = NoSuchPropertyException.class )
58 public void getIndexedUnknown()
59 {
60 on( testBean ).getIndexed( "unknown" );
61 }
62
63 @Test( expected = IllegalArgumentException.class )
64 public void getIndexedNegative()
65 {
66 on( testBean ).getIndexed( "intIndexed" ).at( -1 );
67 }
68
69 @Test
70 public void getIndexed()
71 {
72 int expected = testBean.getIntIndexed( 0 );
73 BeanAccessor<?> accessor = on( testBean ).getIndexed( "intIndexed" ).at( 0 );
74 assertNotNull( accessor );
75 assertEquals( expected, accessor.get() );
76 }
77
78 @Test( expected = PropertyGetterInvocationException.class )
79 public void getExceptionIndexed()
80 {
81 on( exceptionBean ).getIndexed( "exceptionIndexed" ).at( 0 );
82 }
83
84 @Test( expected = NoSuchPropertyException.class )
85 public void getPrivateIndexed()
86 {
87 on( exceptionBean ).getIndexed( "privateIndexed" );
88 }
89
90 @Test( expected = NoSuchPropertyException.class )
91 public void getProtectedIndexed()
92 {
93 on( exceptionBean ).getIndexed( "protecedIndexed" );
94 }
95
96 @Test( expected = NoSuchPropertyException.class )
97 public void getDefaultIndexed()
98 {
99 on( exceptionBean ).getIndexed( "defaultIndexed" );
100 }
101
102 }