| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.commons.beanutils; |
| 18 |
|
|
| 19 |
|
import java.util.HashMap; |
| 20 |
|
import java.util.TreeMap; |
| 21 |
|
import java.util.ArrayList; |
| 22 |
|
import java.util.LinkedList; |
| 23 |
|
import java.lang.reflect.InvocationTargetException; |
| 24 |
|
import junit.framework.TestCase; |
| 25 |
|
import junit.framework.Test; |
| 26 |
|
import junit.framework.TestSuite; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@author |
| 32 |
|
|
|
|
|
| 92.9% |
Uncovered Elements: 14 (198) |
Complexity: 34 |
Complexity Density: 0.19 |
|
| 33 |
|
public class LazyDynaBeanTestCase extends TestCase { |
| 34 |
|
|
| 35 |
|
protected LazyDynaBean bean = null; |
| 36 |
|
protected LazyDynaClass dynaClass = null; |
| 37 |
|
protected String testProperty = "myProperty"; |
| 38 |
|
protected String testPropertyA = "myProperty-A"; |
| 39 |
|
protected String testPropertyB = "myProperty-B"; |
| 40 |
|
protected String testString1 = "myStringValue-1"; |
| 41 |
|
protected String testString2 = "myStringValue-2"; |
| 42 |
|
protected Integer testInteger1 = new Integer(30); |
| 43 |
|
protected Integer testInteger2 = new Integer(40); |
| 44 |
|
protected String testKey = "myKey"; |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@param |
| 52 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
16
|
public LazyDynaBeanTestCase(String name) {... |
| 54 |
16
|
super(name); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 62 |
0
|
public static void main(String[] args) {... |
| 63 |
0
|
junit.textui.TestRunner.run(suite()); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
1
|
public static Test suite() {... |
| 70 |
1
|
return (new TestSuite(LazyDynaBeanTestCase.class)); |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 76 |
16
|
public void setUp() throws Exception {... |
| 77 |
16
|
bean = new LazyDynaBean(); |
| 78 |
16
|
dynaClass = (LazyDynaClass)bean.getDynaClass(); |
| 79 |
16
|
dynaClass.setReturnNull(true); |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
16
|
public void tearDown() {... |
| 86 |
16
|
bean = null; |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
1
PASS
|
|
| 94 |
1
|
public void testSimpleProperty() {... |
| 95 |
|
|
| 96 |
|
|
| 97 |
1
|
assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 98 |
1
|
assertNull("Check Value is null", bean.get(testProperty)); |
| 99 |
|
|
| 100 |
|
|
| 101 |
1
|
bean.set(testProperty, testInteger1); |
| 102 |
1
|
assertEquals("Check First Value is correct", testInteger1, bean.get(testProperty)); |
| 103 |
1
|
assertEquals("Check Property type is correct", Integer.class, dynaClass.getDynaProperty(testProperty).getType()); |
| 104 |
|
|
| 105 |
|
|
| 106 |
1
|
bean.set(testProperty, testInteger2); |
| 107 |
1
|
assertEquals("Check Second Value is correct", testInteger2, bean.get(testProperty)); |
| 108 |
|
|
| 109 |
|
|
| 110 |
1
|
try { |
| 111 |
1
|
bean.set(testProperty, testString1); |
| 112 |
0
|
fail("expected ConversionException trying to set an Integer property to a String"); |
| 113 |
|
} catch (ConversionException expected) { |
| 114 |
|
|
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 122 |
1
|
public void testNullProperty() {... |
| 123 |
|
|
| 124 |
|
|
| 125 |
1
|
assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 126 |
1
|
assertNull("Check Value is null", bean.get(testProperty)); |
| 127 |
|
|
| 128 |
|
|
| 129 |
1
|
bean.set(testProperty, null); |
| 130 |
1
|
assertNull("Check Value is still null", bean.get(testProperty)); |
| 131 |
|
|
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1
PASS
|
|
| 137 |
1
|
public void testSimplePropertyRestricted() {... |
| 138 |
|
|
| 139 |
|
|
| 140 |
1
|
dynaClass.setRestricted(true); |
| 141 |
1
|
assertTrue("Check MutableDynaClass is restricted", dynaClass.isRestricted()); |
| 142 |
|
|
| 143 |
|
|
| 144 |
1
|
assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 145 |
1
|
assertNull("Check Value is null", bean.get(testProperty)); |
| 146 |
|
|
| 147 |
|
|
| 148 |
1
|
try { |
| 149 |
1
|
bean.set(testProperty, testString1); |
| 150 |
0
|
fail("expected IllegalArgumentException trying to add new property to restricted DynaClass"); |
| 151 |
|
} catch (IllegalArgumentException expected) { |
| 152 |
|
|
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 160 |
1
|
public void testMappedPropertyDefault() {... |
| 161 |
|
|
| 162 |
|
|
| 163 |
1
|
assertNull("Check Mapped Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 164 |
1
|
assertNull("Check Map is null", bean.get(testProperty)); |
| 165 |
1
|
assertNull("Check Mapped Value is null", bean.get(testProperty, testKey)); |
| 166 |
|
|
| 167 |
|
|
| 168 |
1
|
bean.set(testProperty, testKey, testInteger1); |
| 169 |
1
|
assertEquals("Check Mapped Property exists", HashMap.class, bean.get(testProperty).getClass()); |
| 170 |
1
|
assertEquals("Check First Mapped Value is correct(a)", testInteger1, bean.get(testProperty, testKey)); |
| 171 |
1
|
assertEquals("Check First Mapped Value is correct(b)", testInteger1, ((HashMap)bean.get(testProperty)).get(testKey)); |
| 172 |
|
|
| 173 |
|
|
| 174 |
1
|
bean.set(testProperty, testKey, testInteger2); |
| 175 |
1
|
assertEquals("Check Second Mapped Value is correct(a)", testInteger2, bean.get(testProperty, testKey)); |
| 176 |
1
|
assertEquals("Check Second Mapped Value is correct(b)", testInteger2, ((HashMap)bean.get(testProperty)).get(testKey)); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
| 182 |
1
|
public void testMappedPropertyTreeMap() {... |
| 183 |
|
|
| 184 |
|
|
| 185 |
1
|
assertNull("Check Mapped Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 186 |
|
|
| 187 |
|
|
| 188 |
1
|
dynaClass.add(testProperty, TreeMap.class); |
| 189 |
1
|
assertTrue("Check Property is mapped", dynaClass.getDynaProperty(testProperty).isMapped()); |
| 190 |
1
|
assertEquals("Check Property is correct type", TreeMap.class, dynaClass.getDynaProperty(testProperty).getType()); |
| 191 |
1
|
assertEquals("Check Mapped Property exists", TreeMap.class, bean.get(testProperty).getClass()); |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
1
|
bean.set(testProperty, testKey, testInteger1); |
| 196 |
1
|
assertEquals("Check Mapped Property exists", TreeMap.class, bean.get(testProperty).getClass()); |
| 197 |
1
|
assertEquals("Check First Mapped Value is correct(a)", testInteger1, bean.get(testProperty, testKey)); |
| 198 |
1
|
assertEquals("Check First Mapped Value is correct(b)", testInteger1, ((TreeMap)bean.get(testProperty)).get(testKey)); |
| 199 |
|
|
| 200 |
|
|
| 201 |
1
|
bean.set(testProperty, testKey, testInteger2); |
| 202 |
1
|
assertEquals("Check Second Mapped Value is correct(a)", testInteger2, bean.get(testProperty, testKey)); |
| 203 |
1
|
assertEquals("Check Second Mapped Value is correct(b)", testInteger2, ((TreeMap)bean.get(testProperty)).get(testKey)); |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 4 |
Complexity Density: 0.4 |
1
PASS
|
|
| 209 |
1
|
public void testMappedPropertyUtils() {... |
| 210 |
|
|
| 211 |
1
|
dynaClass.setReturnNull(false); |
| 212 |
|
|
| 213 |
|
|
| 214 |
1
|
assertFalse("Check Mapped Property doesn't exist", dynaClass.isDynaProperty(testProperty)); |
| 215 |
1
|
assertNull("Check Map is null", bean.get(testProperty)); |
| 216 |
1
|
assertNull("Check Mapped Value is null", bean.get(testProperty, testKey)); |
| 217 |
|
|
| 218 |
|
|
| 219 |
1
|
try { |
| 220 |
1
|
PropertyUtils.setProperty(bean, testProperty+"("+testKey+")", testString1); |
| 221 |
|
} |
| 222 |
|
catch (NoSuchMethodException ex) { |
| 223 |
0
|
fail("testIndexedPropertyUtils threw "+ex); |
| 224 |
|
} |
| 225 |
|
catch (InvocationTargetException ex) { |
| 226 |
0
|
fail("testIndexedPropertyUtils threw "+ex); |
| 227 |
|
} |
| 228 |
|
catch (IllegalAccessException ex) { |
| 229 |
0
|
fail("testIndexedPropertyUtils threw "+ex); |
| 230 |
|
} |
| 231 |
|
|
| 232 |
|
|
| 233 |
1
|
assertEquals("Check Mapped Bean Value is correct", testString1, bean.get(testProperty, testKey)); |
| 234 |
|
|
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
|
| 238 |
|
|
| 239 |
|
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1
PASS
|
|
| 240 |
1
|
public void testMappedPropertyRestricted() {... |
| 241 |
|
|
| 242 |
|
|
| 243 |
1
|
dynaClass.setRestricted(true); |
| 244 |
1
|
assertTrue("Check MutableDynaClass is restricted", dynaClass.isRestricted()); |
| 245 |
|
|
| 246 |
|
|
| 247 |
1
|
assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 248 |
1
|
assertNull("Check Value is null", bean.get(testProperty)); |
| 249 |
|
|
| 250 |
|
|
| 251 |
1
|
try { |
| 252 |
1
|
bean.set(testProperty, testKey, testInteger1); |
| 253 |
0
|
fail("expected IllegalArgumentException trying to add new property to restricted MutableDynaClass"); |
| 254 |
|
} catch (IllegalArgumentException expected) { |
| 255 |
|
|
| 256 |
|
} |
| 257 |
|
|
| 258 |
|
} |
| 259 |
|
|
| 260 |
|
|
| 261 |
|
|
| 262 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1
PASS
|
|
| 263 |
1
|
public void testMappedInvalidType() {... |
| 264 |
1
|
dynaClass.add(testProperty, String.class); |
| 265 |
1
|
assertFalse("Check Property is not mapped", dynaClass.getDynaProperty(testProperty).isMapped()); |
| 266 |
1
|
try { |
| 267 |
1
|
bean.set(testProperty, testKey, testInteger1); |
| 268 |
0
|
fail("set(property, key, value) should have thrown IllegalArgumentException"); |
| 269 |
|
} catch (IllegalArgumentException expected) { |
| 270 |
|
|
| 271 |
|
} |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
|
| 275 |
|
|
| 276 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
| 277 |
1
|
public void testIndexedPropertyDefault() {... |
| 278 |
|
|
| 279 |
1
|
int index = 3; |
| 280 |
|
|
| 281 |
|
|
| 282 |
1
|
assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 283 |
1
|
assertNull("Check Indexed Property is null", bean.get(testProperty)); |
| 284 |
1
|
assertNull("Check Indexed value is null", bean.get(testProperty, index)); |
| 285 |
|
|
| 286 |
|
|
| 287 |
1
|
bean.set(testProperty, index, testInteger1); |
| 288 |
1
|
assertNotNull("Check Indexed Property is not null", bean.get(testProperty)); |
| 289 |
1
|
assertEquals("Check Indexed Property is correct type", ArrayList.class, bean.get(testProperty).getClass()); |
| 290 |
1
|
assertEquals("Check First Indexed Value is correct", testInteger1, bean.get(testProperty, index)); |
| 291 |
1
|
assertEquals("Check First Array length is correct", new Integer(index+1), new Integer(((ArrayList)bean.get(testProperty)).size())); |
| 292 |
|
|
| 293 |
|
|
| 294 |
1
|
index = index + 2; |
| 295 |
1
|
bean.set(testProperty, index, testString1); |
| 296 |
1
|
assertEquals("Check Second Indexed Value is correct", testString1, bean.get(testProperty, index)); |
| 297 |
1
|
assertEquals("Check Second Array length is correct", new Integer(index+1), new Integer(((ArrayList)bean.get(testProperty)).size())); |
| 298 |
|
} |
| 299 |
|
|
| 300 |
|
|
| 301 |
|
|
| 302 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1
PASS
|
|
| 303 |
1
|
public void testIndexedLinkedList() {... |
| 304 |
|
|
| 305 |
1
|
int index = 3; |
| 306 |
|
|
| 307 |
|
|
| 308 |
1
|
assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 309 |
1
|
assertNull("Check Indexed Property is null", bean.get(testProperty)); |
| 310 |
|
|
| 311 |
|
|
| 312 |
1
|
dynaClass.add(testProperty, LinkedList.class); |
| 313 |
1
|
assertTrue("Check Property is indexed", dynaClass.getDynaProperty(testProperty).isIndexed()); |
| 314 |
1
|
assertEquals("Check Property is correct type", LinkedList.class, dynaClass.getDynaProperty(testProperty).getType()); |
| 315 |
1
|
assertEquals("Check Property type is correct", LinkedList.class, bean.get(testProperty).getClass()); |
| 316 |
|
|
| 317 |
|
|
| 318 |
1
|
bean.set(testProperty, index, testString1); |
| 319 |
1
|
assertEquals("Check Property type is correct", LinkedList.class, bean.get(testProperty).getClass()); |
| 320 |
1
|
assertEquals("Check First Indexed Value is correct", testString1, bean.get(testProperty, index)); |
| 321 |
1
|
assertEquals("Check First Array length is correct", new Integer(index+1), new Integer(((LinkedList)bean.get(testProperty)).size())); |
| 322 |
|
|
| 323 |
|
|
| 324 |
1
|
index = index + 2; |
| 325 |
1
|
bean.set(testProperty, index, testInteger1); |
| 326 |
1
|
assertEquals("Check Second Indexed Value is correct", testInteger1, bean.get(testProperty, index)); |
| 327 |
1
|
assertEquals("Check Second Array length is correct", new Integer(index+1), new Integer(((LinkedList)bean.get(testProperty)).size())); |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
|
| 331 |
|
|
| 332 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
| 333 |
1
|
public void testIndexedPrimitiveArray() {... |
| 334 |
|
|
| 335 |
1
|
int index = 3; |
| 336 |
1
|
int[] primitiveArray = new int[0]; |
| 337 |
|
|
| 338 |
|
|
| 339 |
1
|
assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 340 |
1
|
assertNull("Check Indexed Property is null", bean.get(testProperty)); |
| 341 |
|
|
| 342 |
|
|
| 343 |
1
|
dynaClass.add(testProperty, primitiveArray.getClass()); |
| 344 |
1
|
assertEquals("Check Indexed Property exists", primitiveArray.getClass(), dynaClass.getDynaProperty(testProperty).getType()); |
| 345 |
1
|
assertEquals("Check Indexed Property is correct type", primitiveArray.getClass(), bean.get(testProperty).getClass()); |
| 346 |
|
|
| 347 |
|
|
| 348 |
1
|
bean.set(testProperty, index, testInteger1); |
| 349 |
1
|
assertNotNull("Check Indexed Property is not null", bean.get(testProperty)); |
| 350 |
1
|
assertEquals("Check Indexed Property is correct type", primitiveArray.getClass(), bean.get(testProperty).getClass()); |
| 351 |
1
|
assertEquals("Check First Indexed Value is correct(a)", testInteger1, bean.get(testProperty, index)); |
| 352 |
1
|
assertEquals("Check First Indexed Value is correct(b)", testInteger1, new Integer(((int[])bean.get(testProperty))[index])); |
| 353 |
1
|
assertEquals("Check Array length is correct", new Integer(index+1), new Integer(((int[])bean.get(testProperty)).length)); |
| 354 |
|
|
| 355 |
|
|
| 356 |
1
|
index = index + 2; |
| 357 |
1
|
bean.set(testProperty, index, testInteger2); |
| 358 |
1
|
assertEquals("Check Second Indexed Value is correct(a)", testInteger2, bean.get(testProperty, index)); |
| 359 |
1
|
assertEquals("Check Second Indexed Value is correct(b)", testInteger2, new Integer(((int[])bean.get(testProperty))[index])); |
| 360 |
1
|
assertEquals("Check Second Array length is correct", new Integer(index+1), new Integer(((int[])bean.get(testProperty)).length)); |
| 361 |
|
|
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
|
| 365 |
|
|
| 366 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1
PASS
|
|
| 367 |
1
|
public void testIndexedObjectArray() {... |
| 368 |
|
|
| 369 |
1
|
int index = 3; |
| 370 |
1
|
Object objectArray = new String[0]; |
| 371 |
|
|
| 372 |
|
|
| 373 |
1
|
assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 374 |
1
|
assertNull("Check Indexed Property is null", bean.get(testProperty)); |
| 375 |
|
|
| 376 |
|
|
| 377 |
1
|
dynaClass.add(testProperty, objectArray.getClass()); |
| 378 |
1
|
assertEquals("Check Indexed Property exists", objectArray.getClass(), dynaClass.getDynaProperty(testProperty).getType()); |
| 379 |
1
|
assertEquals("Check Indexed Property is correct type", objectArray.getClass(), bean.get(testProperty).getClass()); |
| 380 |
|
|
| 381 |
|
|
| 382 |
1
|
bean.set(testProperty, index, testString1); |
| 383 |
1
|
assertNotNull("Check Indexed Property is not null", bean.get(testProperty)); |
| 384 |
1
|
assertEquals("Check Indexed Property is correct type", objectArray.getClass(), bean.get(testProperty).getClass()); |
| 385 |
1
|
assertEquals("Check First Indexed Value is correct(a)", testString1, bean.get(testProperty, index)); |
| 386 |
1
|
assertEquals("Check First Indexed Value is correct(b)", testString1, ((String[])bean.get(testProperty))[index]); |
| 387 |
1
|
assertEquals("Check Array length is correct", new Integer(index+1), new Integer(((String[])bean.get(testProperty)).length)); |
| 388 |
|
|
| 389 |
|
|
| 390 |
1
|
index = index + 2; |
| 391 |
1
|
bean.set(testProperty, index, testString2); |
| 392 |
1
|
assertEquals("Check Second Indexed Value is correct(a)", testString2, bean.get(testProperty, index)); |
| 393 |
1
|
assertEquals("Check Second Indexed Value is correct(b)", testString2, ((String[])bean.get(testProperty))[index]); |
| 394 |
1
|
assertEquals("Check Second Array length is correct", new Integer(index+1), new Integer(((String[])bean.get(testProperty)).length)); |
| 395 |
|
} |
| 396 |
|
|
| 397 |
|
|
| 398 |
|
|
| 399 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
1
PASS
|
|
| 400 |
1
|
public void testIndexedDynaBeanArray() {... |
| 401 |
|
|
| 402 |
1
|
int index = 3; |
| 403 |
1
|
Object objectArray = new LazyDynaMap[0]; |
| 404 |
|
|
| 405 |
|
|
| 406 |
1
|
assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 407 |
1
|
assertNull("Check Indexed Property is null", bean.get(testProperty)); |
| 408 |
|
|
| 409 |
|
|
| 410 |
1
|
dynaClass.add(testProperty, objectArray.getClass()); |
| 411 |
1
|
assertEquals("Check Indexed Property exists", objectArray.getClass(), dynaClass.getDynaProperty(testProperty).getType()); |
| 412 |
1
|
assertEquals("Check Indexed Property is correct type", objectArray.getClass(), bean.get(testProperty).getClass()); |
| 413 |
|
|
| 414 |
|
|
| 415 |
5
|
for (int i = index; i >= 0; i--) { |
| 416 |
4
|
assertEquals("Check Array Components initialized", LazyDynaMap.class, bean.get(testProperty, index).getClass()); |
| 417 |
|
} |
| 418 |
|
|
| 419 |
1
|
dynaClass.add(testPropertyB, objectArray.getClass()); |
| 420 |
1
|
LazyDynaMap newMap = new LazyDynaMap(); |
| 421 |
1
|
newMap.set(testPropertyB, testString2); |
| 422 |
1
|
bean.set(testPropertyA, index, newMap); |
| 423 |
1
|
assertEquals("Check Indexed Value is correct(a)", testString2, ((DynaBean)bean.get(testPropertyA, index)).get(testPropertyB)); |
| 424 |
|
|
| 425 |
|
} |
| 426 |
|
|
| 427 |
|
|
| 428 |
|
|
| 429 |
|
|
|
|
|
| 72.7% |
Uncovered Elements: 3 (11) |
Complexity: 4 |
Complexity Density: 0.36 |
1
PASS
|
|
| 430 |
1
|
public void testIndexedPropertyUtils() {... |
| 431 |
|
|
| 432 |
1
|
int index = 3; |
| 433 |
1
|
dynaClass.setReturnNull(false); |
| 434 |
|
|
| 435 |
|
|
| 436 |
1
|
assertFalse("Check Indexed Property doesn't exist", dynaClass.isDynaProperty(testProperty)); |
| 437 |
1
|
assertNull("Check Indexed Property is null", bean.get(testProperty)); |
| 438 |
1
|
assertNull("Check Indexed value is null", bean.get(testProperty, index)); |
| 439 |
|
|
| 440 |
|
|
| 441 |
1
|
try { |
| 442 |
1
|
PropertyUtils.setProperty(bean, testProperty+"["+index+"]", testString1); |
| 443 |
|
} |
| 444 |
|
catch (NoSuchMethodException ex) { |
| 445 |
0
|
fail("testIndexedPropertyUtils threw "+ex); |
| 446 |
|
} |
| 447 |
|
catch (InvocationTargetException ex) { |
| 448 |
0
|
fail("testIndexedPropertyUtils threw "+ex); |
| 449 |
|
} |
| 450 |
|
catch (IllegalAccessException ex) { |
| 451 |
0
|
fail("testIndexedPropertyUtils threw "+ex); |
| 452 |
|
} |
| 453 |
|
|
| 454 |
|
|
| 455 |
1
|
assertEquals("Check Indexed Bean Value is correct", testString1, bean.get(testProperty, index)); |
| 456 |
|
|
| 457 |
|
} |
| 458 |
|
|
| 459 |
|
|
| 460 |
|
|
| 461 |
|
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
1
PASS
|
|
| 462 |
1
|
public void testIndexedPropertyRestricted() {... |
| 463 |
|
|
| 464 |
1
|
int index = 3; |
| 465 |
|
|
| 466 |
|
|
| 467 |
1
|
dynaClass.setRestricted(true); |
| 468 |
1
|
assertTrue("Check MutableDynaClass is restricted", dynaClass.isRestricted()); |
| 469 |
|
|
| 470 |
|
|
| 471 |
1
|
assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty)); |
| 472 |
1
|
assertNull("Check Value is null", bean.get(testProperty)); |
| 473 |
|
|
| 474 |
|
|
| 475 |
1
|
try { |
| 476 |
1
|
bean.set(testProperty, index, testInteger1); |
| 477 |
0
|
fail("expected IllegalArgumentException trying to add new property to restricted MutableDynaClass"); |
| 478 |
|
} catch (IllegalArgumentException expected) { |
| 479 |
|
|
| 480 |
|
} |
| 481 |
|
|
| 482 |
|
} |
| 483 |
|
|
| 484 |
|
|
| 485 |
|
|
| 486 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1
PASS
|
|
| 487 |
1
|
public void testIndexedInvalidType() {... |
| 488 |
1
|
int index = 3; |
| 489 |
1
|
dynaClass.add(testProperty, String.class); |
| 490 |
1
|
assertFalse("Check Property is not indexed", dynaClass.getDynaProperty(testProperty).isIndexed()); |
| 491 |
1
|
try { |
| 492 |
1
|
bean.set(testProperty, index, testString1); |
| 493 |
0
|
fail("set(property, index, value) should have thrown IllegalArgumentException"); |
| 494 |
|
} catch (IllegalArgumentException expected) { |
| 495 |
|
|
| 496 |
|
} |
| 497 |
|
} |
| 498 |
|
|
| 499 |
|
} |