|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -518,6 +518,36 @@ public void testStringArrayPropertyWithCustomStringDelimiter() throws Exception
|
518 | 518 | assertTrue("correct values", pt.stringArray[0].equals("a1") && pt.stringArray[1].equals("b2"));
|
519 | 519 | }
|
520 | 520 |
|
| 521 | + @Test |
| 522 | + public void testStringArrayAutoGrow() throws Exception { |
| 523 | + StringArrayBean target = new StringArrayBean(); |
| 524 | + BeanWrapper bw = new BeanWrapperImpl(target); |
| 525 | + bw.setAutoGrowNestedPaths(true); |
| 526 | + |
| 527 | + bw.setPropertyValue("array[0]", "Test0"); |
| 528 | + assertEquals(1, target.getArray().length); |
| 529 | + |
| 530 | + bw.setPropertyValue("array[2]", "Test2"); |
| 531 | + assertEquals(3, target.getArray().length); |
| 532 | + assertTrue("correct values", target.getArray()[0].equals("Test0") && target.getArray()[1] == null && |
| 533 | + target.getArray()[2].equals("Test2")); |
| 534 | + } |
| 535 | + |
| 536 | + @Test |
| 537 | + public void testPrimitiveArrayAutoGrow() throws Exception { |
| 538 | + PrimitiveArrayBean target = new PrimitiveArrayBean(); |
| 539 | + BeanWrapper bw = new BeanWrapperImpl(target); |
| 540 | + bw.setAutoGrowNestedPaths(true); |
| 541 | + |
| 542 | + bw.setPropertyValue("array[0]", 1); |
| 543 | + assertEquals(1, target.getArray().length); |
| 544 | + |
| 545 | + bw.setPropertyValue("array[2]", 3); |
| 546 | + assertEquals(3, target.getArray().length); |
| 547 | + assertTrue("correct values", target.getArray()[0] == 1 && target.getArray()[1] == 0 && |
| 548 | + target.getArray()[2] == 3); |
| 549 | + } |
| 550 | + |
521 | 551 | @Test
|
522 | 552 | public void testStringPropertyWithCustomEditor() throws Exception {
|
523 | 553 | TestBean tb = new TestBean();
|
@@ -1723,6 +1753,20 @@ public void setArray(int[] array) {
|
1723 | 1753 | }
|
1724 | 1754 | }
|
1725 | 1755 |
|
| 1756 | + @SuppressWarnings("unused") |
| 1757 | + private static class StringArrayBean { |
| 1758 | + |
| 1759 | + private String[] array; |
| 1760 | + |
| 1761 | + public String[] getArray() { |
| 1762 | + return array; |
| 1763 | + } |
| 1764 | + |
| 1765 | + public void setArray(String[] array) { |
| 1766 | + this.array = array; |
| 1767 | + } |
| 1768 | + } |
| 1769 | + |
1726 | 1770 |
|
1727 | 1771 | @SuppressWarnings("unused")
|
1728 | 1772 | private static class NumberPropertyBean {
|
|
0 commit comments