Clover Coverage Report - Commons BeanUtils 1.8.3-kuali-SNAPSHOT
Coverage timestamp: Thu Jun 9 2011 14:31:17 EDT
81   322   40   3
0   171   0.49   27
27     1.48  
1    
 
  BeanPropertyValueChangeClosureTestCase       Line # 28 81 0% 40 13 88% 0.8796296
 
  (26)
 
1    /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17   
18    package org.apache.commons.beanutils;
19   
20    import junit.framework.TestCase;
21   
22   
23    /**
24    * Test cases for <code>BeanPropertyValueChangeClosure</code>.
25    *
26    * @author Norm Deane
27    */
 
28    public class BeanPropertyValueChangeClosureTestCase extends TestCase {
29   
30    private static final Integer expectedIntegerValue = new Integer(123);
31    private static final Float expectedFloatValue = new Float(123.123f);
32    private static final Double expectedDoubleValue = new Double(567879.12344d);
33    private static final Boolean expectedBooleanValue = Boolean.TRUE;
34    private static final Byte expectedByteValue = new Byte("12");
35   
36    /**
37    * Constructor for BeanPropertyValueChangeClosureTest.
38    *
39    * @param name Name of this test case.
40    */
 
41  26 toggle public BeanPropertyValueChangeClosureTestCase(String name) {
42  26 super(name);
43    }
44   
45    /**
46    * Test execute with simple float property and Float value.
47    */
 
48  1 toggle public void testExecuteWithSimpleFloatPropertyAndFloatValue() {
49  1 TestBean testBean = new TestBean();
50  1 new BeanPropertyValueChangeClosure("floatProperty", expectedFloatValue).execute(testBean);
51  1 assertTrue(expectedFloatValue.floatValue() == testBean.getFloatProperty());
52    }
53   
54    /**
55    * Test execute with simple float property and String value.
56    */
 
57  1 toggle public void testExecuteWithSimpleFloatPropertyAndStringValue() {
58  1 try {
59  1 new BeanPropertyValueChangeClosure("floatProperty", "123").execute(new TestBean());
60  0 fail("Should have thrown an IllegalArgumentException");
61    } catch (IllegalArgumentException e) {
62    /* this is what we expect */
63    }
64    }
65   
66    /**
67    * Test execute with simple float property and Double value.
68    */
 
69  1 toggle public void testExecuteWithSimpleFloatPropertyAndDoubleValue() {
70  1 try {
71  1 new BeanPropertyValueChangeClosure("floatProperty", expectedDoubleValue).execute(new TestBean());
72  0 fail("Should have thrown an IllegalArgumentException");
73    } catch (IllegalArgumentException e) {
74    /* this is what we expect */
75    }
76    }
77   
78    /**
79    * Test execute with simple float property and Integer value.
80    */
 
81  1 toggle public void testExecuteWithSimpleFloatPropertyAndIntegerValue() {
82  1 TestBean testBean = new TestBean();
83  1 new BeanPropertyValueChangeClosure("floatProperty", expectedIntegerValue).execute(testBean);
84  1 assertTrue(expectedIntegerValue.floatValue() == testBean.getFloatProperty());
85    }
86   
87    /**
88    * Test execute with simple double property and Double value.
89    */
 
90  1 toggle public void testExecuteWithSimpleDoublePropertyAndDoubleValue() {
91  1 TestBean testBean = new TestBean();
92  1 new BeanPropertyValueChangeClosure("doubleProperty", expectedDoubleValue).execute(testBean);
93  1 assertTrue(expectedDoubleValue.doubleValue() == testBean.getDoubleProperty());
94    }
95   
96    /**
97    * Test execute with simple double property and String value.
98    */
 
99  1 toggle public void testExecuteWithSimpleDoublePropertyAndStringValue() {
100  1 try {
101  1 new BeanPropertyValueChangeClosure("doubleProperty", "123").execute(new TestBean());
102  0 fail("Should have thrown an IllegalArgumentException");
103    } catch (IllegalArgumentException e) {
104    /* this is what we expect */
105    }
106    }
107   
108    /**
109    * Test execute with simple double property and Float value.
110    */
 
111  1 toggle public void testExecuteWithSimpleDoublePropertyAndFloatValue() {
112  1 TestBean testBean = new TestBean();
113  1 new BeanPropertyValueChangeClosure("doubleProperty", expectedFloatValue).execute(testBean);
114  1 assertTrue(expectedFloatValue.doubleValue() == testBean.getDoubleProperty());
115    }
116   
117    /**
118    * Test execute with simple double property and Integer value.
119    */
 
120  1 toggle public void testExecuteWithSimpleDoublePropertyAndIntegerValue() {
121  1 TestBean testBean = new TestBean();
122  1 new BeanPropertyValueChangeClosure("doubleProperty", expectedIntegerValue).execute(testBean);
123  1 assertTrue(expectedIntegerValue.doubleValue() == testBean.getDoubleProperty());
124    }
125   
126    /**
127    * Test execute with simple int property and Double value.
128    */
 
129  1 toggle public void testExecuteWithSimpleIntPropertyAndDoubleValue() {
130  1 try {
131  1 new BeanPropertyValueChangeClosure("intProperty", expectedDoubleValue).execute(new TestBean());
132  0 fail("Should have thrown an IllegalArgumentException");
133    } catch (IllegalArgumentException e) {
134    /* this is what we expect */
135    }
136    }
137   
138    /**
139    * Test execute with simple int property and String value.
140    */
 
141  1 toggle public void testExecuteWithSimpleIntPropertyAndStringValue() {
142  1 try {
143  1 new BeanPropertyValueChangeClosure("intProperty", "123").execute(new TestBean());
144  0 fail("Should have thrown an IllegalArgumentException");
145    } catch (IllegalArgumentException e) {
146    /* this is what we expect */
147    }
148    }
149   
150    /**
151    * Test execute with simple int property and Float value.
152    */
 
153  1 toggle public void testExecuteWithSimpleIntPropertyAndFloatValue() {
154  1 try {
155  1 new BeanPropertyValueChangeClosure("intProperty", expectedFloatValue).execute(new TestBean());
156  0 fail("Should have thrown an IllegalArgumentException");
157    } catch (IllegalArgumentException e) {
158    /* this is what we expect */
159    }
160    }
161   
162    /**
163    * Test execute with simple int property and Integer value.
164    */
 
165  1 toggle public void testExecuteWithSimpleIntPropertyAndIntegerValue() {
166  1 TestBean testBean = new TestBean();
167  1 new BeanPropertyValueChangeClosure("intProperty", expectedIntegerValue).execute(testBean);
168  1 assertTrue(expectedIntegerValue.intValue() == testBean.getIntProperty());
169    }
170   
171    /**
172    * Test execute with simple boolean property and Boolean value.
173    */
 
174  1 toggle public void testExecuteWithSimpleBooleanPropertyAndBooleanValue() {
175  1 TestBean testBean = new TestBean();
176  1 new BeanPropertyValueChangeClosure("booleanProperty", expectedBooleanValue).execute(testBean);
177  1 assertTrue(expectedBooleanValue.booleanValue() == testBean.getBooleanProperty());
178    }
179   
180    /**
181    * Test execute with simple boolean property and String value.
182    */
 
183  1 toggle public void testExecuteWithSimpleBooleanPropertyAndStringValue() {
184  1 try {
185  1 new BeanPropertyValueChangeClosure("booleanProperty", "true").execute(new TestBean());
186  0 fail("Should have thrown an IllegalArgumentException");
187    } catch (IllegalArgumentException e) {
188    /* this is what we expect */
189    }
190    }
191   
192    /**
193    * Test execute with simple byte property and Byte value.
194    */
 
195  1 toggle public void testExecuteWithSimpleBytePropertyAndByteValue() {
196  1 TestBean testBean = new TestBean();
197  1 new BeanPropertyValueChangeClosure("byteProperty", expectedByteValue).execute(testBean);
198  1 assertTrue(expectedByteValue.byteValue() == testBean.getByteProperty());
199    }
200   
201    /**
202    * Test execute with simple boolean property and String value.
203    */
 
204  1 toggle public void testExecuteWithSimpleBytePropertyAndStringValue() {
205  1 try {
206  1 new BeanPropertyValueChangeClosure("byteProperty", "foo").execute(new TestBean());
207  0 fail("Should have thrown an IllegalArgumentException");
208    } catch (IllegalArgumentException e) {
209    /* this is what we expect */
210    }
211    }
212   
213    /**
214    * Test execute with simple primitive property and null value.
215    */
 
216  1 toggle public void testExecuteWithSimplePrimitivePropertyAndNullValue() {
217  1 try {
218  1 new BeanPropertyValueChangeClosure("intProperty", null).execute(new TestBean());
219  0 fail("Should have thrown an IllegalArgumentException");
220    } catch (IllegalArgumentException e) {
221    /* this is what we expect */
222    }
223    }
224   
225    /**
226    * Test execute with read only property.
227    */
 
228  1 toggle public void testExecuteWithReadOnlyProperty() {
229  1 try {
230  1 new BeanPropertyValueChangeClosure("readOnlyProperty", "foo").execute(new TestBean());
231  0 fail("Should have thrown an IllegalArgumentException");
232    } catch (IllegalArgumentException e) {
233    /* this is what we expect */
234    }
235    }
236   
237    /**
238    * Test execute with write only property.
239    */
 
240  1 toggle public void testExecuteWithWriteOnlyProperty() {
241  1 TestBean testBean = new TestBean();
242  1 new BeanPropertyValueChangeClosure("writeOnlyProperty", "foo").execute(testBean);
243  1 assertEquals("foo", testBean.getWriteOnlyPropertyValue());
244    }
245   
246    /**
247    * Test execute with a nested property.
248    */
 
249  1 toggle public void testExecuteWithNestedProperty() {
250  1 TestBean testBean = new TestBean();
251  1 new BeanPropertyValueChangeClosure("nested.stringProperty", "bar").execute(testBean);
252  1 assertEquals("bar", testBean.getNested().getStringProperty());
253    }
254   
255    /**
256    * Test execute with a nested property and null in the property path.
257    */
 
258  1 toggle public void testExecuteWithNullInPropertyPath() {
259  1 try {
260  1 new BeanPropertyValueChangeClosure("anotherNested.stringProperty", "foo").execute(new TestBean());
261  0 fail("Should have thrown an IllegalArgumentException");
262    } catch (IllegalArgumentException e) {
263    /* this is what we expect */
264    }
265    }
266   
267    /**
268    * Test execute with a nested property and null in the property path and ignoreNull = true.
269    */
 
270  1 toggle public void testExecuteWithNullInPropertyPathAngIgnoreTrue() {
271  1 TestBean testBean = new TestBean();
272   
273    // create a closure that will attempt to set a property on the null bean in the path
274  1 BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("anotherNested.stringProperty",
275    "Should ignore exception", true);
276   
277  1 try {
278  1 closure.execute(testBean);
279    } catch (IllegalArgumentException e) {
280  0 fail("Should have ignored the exception.");
281    }
282    }
283   
284    /**
285    * Test execute with indexed property.
286    */
 
287  1 toggle public void testExecuteWithIndexedProperty() {
288  1 TestBean testBean = new TestBean();
289  1 new BeanPropertyValueChangeClosure("intIndexed[0]", expectedIntegerValue).execute(testBean);
290  1 assertTrue(expectedIntegerValue.intValue() == testBean.getIntIndexed(0));
291    }
292   
293    /**
294    * Test execute with mapped property.
295    */
 
296  1 toggle public void testExecuteWithMappedProperty() {
297  1 TestBean testBean = new TestBean();
298  1 new BeanPropertyValueChangeClosure("mappedProperty(fred)", "barney").execute(testBean);
299  1 assertEquals("barney", testBean.getMappedProperty("fred"));
300    }
301   
302    /**
303    * Test execute with a simple String property.
304    */
 
305  1 toggle public void testExecuteWithSimpleStringProperty() {
306  1 TestBean testBean = new TestBean();
307  1 new BeanPropertyValueChangeClosure("stringProperty", "barney").execute(testBean);
308  1 assertEquals("barney", testBean.getStringProperty());
309    }
310   
311    /**
312    * Test execute with an invalid property name.
313    */
 
314  1 toggle public void testExecuteWithInvalidPropertyName() {
315  1 try {
316  1 new BeanPropertyValueChangeClosure("bogusProperty", "foo").execute(new TestBean());
317  0 fail("Should have thrown an IllegalArgumentException");
318    } catch (IllegalArgumentException e) {
319    /* this is what we expect */
320    }
321    }
322    }