| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package org.apache.commons.beanutils; |
| 19 |
|
|
| 20 |
|
import junit.framework.TestCase; |
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
@author |
| 27 |
|
|
|
|
|
| 88% |
Uncovered Elements: 13 (108) |
Complexity: 40 |
Complexity Density: 0.49 |
|
| 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 |
|
|
| 38 |
|
|
| 39 |
|
@param |
| 40 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 41 |
26
|
public BeanPropertyValueChangeClosureTestCase(String name) {... |
| 42 |
26
|
super(name); |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 48 |
1
|
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 |
|
|
| 56 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 57 |
1
|
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 |
|
|
| 63 |
|
} |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 69 |
1
|
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 |
|
|
| 75 |
|
} |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 81 |
1
|
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 |
|
|
| 89 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 90 |
1
|
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 |
|
|
| 98 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 99 |
1
|
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 |
|
|
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 111 |
1
|
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 |
|
|
| 119 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 120 |
1
|
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 |
|
|
| 128 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 129 |
1
|
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 |
|
|
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 141 |
1
|
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 |
|
|
| 147 |
|
} |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 153 |
1
|
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 |
|
|
| 159 |
|
} |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 165 |
1
|
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 |
|
|
| 173 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 174 |
1
|
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 |
|
|
| 182 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 183 |
1
|
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 |
|
|
| 189 |
|
} |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 195 |
1
|
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 |
|
|
| 203 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 204 |
1
|
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 |
|
|
| 210 |
|
} |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 216 |
1
|
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 |
|
|
| 222 |
|
} |
| 223 |
|
} |
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
| 227 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 228 |
1
|
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 |
|
|
| 234 |
|
} |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
|
| 238 |
|
|
| 239 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 240 |
1
|
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 |
|
|
| 248 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 249 |
1
|
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 |
|
|
| 257 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 258 |
1
|
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 |
|
|
| 264 |
|
} |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
|
| 268 |
|
|
| 269 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1
PASS
|
|
| 270 |
1
|
public void testExecuteWithNullInPropertyPathAngIgnoreTrue() {... |
| 271 |
1
|
TestBean testBean = new TestBean(); |
| 272 |
|
|
| 273 |
|
|
| 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 |
|
|
| 286 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 287 |
1
|
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 |
|
|
| 295 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 296 |
1
|
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 |
|
|
| 304 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 305 |
1
|
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 |
|
|
| 313 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 314 |
1
|
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 |
|
|
| 320 |
|
} |
| 321 |
|
} |
| 322 |
|
} |