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.assertTrue;
22
23 import org.apache.commons.beanutils2.testbeans.TestBean;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 public class SetIndexedPropertyTestCase
29 {
30
31 private TestBean testBean;
32
33 @Before
34 public void setUp()
35 {
36 testBean = new TestBean();
37 }
38
39 @After
40 public void tearDown()
41 {
42 testBean = null;
43 }
44
45 @Test( expected = IllegalArgumentException.class )
46 public void setIndexedNegative()
47 throws Exception
48 {
49 on( testBean ).setIndexed( "intIndexed" ).at( -1 );
50 }
51
52 @Test( expected = NoSuchPropertyException.class )
53 public void setIndexedUnknown()
54 throws Exception
55 {
56 on( testBean ).setIndexed( "unkown" );
57 }
58
59 @Test
60 public void setIntIndexed()
61 throws Exception
62 {
63 on( testBean ).setIndexed( "intIndexed" ).at( 1 ).with( 4711 );
64 assertTrue( testBean.getIntIndexed( 1 ) == 4711 );
65 }
66
67 @Test( expected = IllegalArgumentException.class )
68 public void setIntIndexedNull()
69 throws Exception
70 {
71 on( testBean ).setIndexed( "intIndexed" ).at( 1 ).with( null );
72 }
73
74 @Test
75 public void setStringIndexed()
76 throws Exception
77 {
78 on( testBean ).setIndexed( "stringIndexed" ).at( 1 ).with( "Hello World!" );
79 assertTrue( testBean.getStringIndexed( 1 ).equals( "Hello World!" ) );
80 }
81
82 @Test
83 public void setStringIndexedNull()
84 throws Exception
85 {
86 on( testBean ).setIndexed( "stringIndexed" ).at( 1 ).with( null );
87 assertTrue( testBean.getStringIndexed( 1 ) == null );
88 }
89
90 @Test( expected = IllegalArgumentException.class )
91 public void setStringIndexedInt()
92 throws Exception
93 {
94 on( testBean ).setIndexed( "stringIndexed" ).at( 1 ).with( 4711 );
95 }
96
97 }