1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2021 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.
28
28
/**
29
29
* @author Keith Donald
30
30
* @author Juergen Hoeller
31
+ * @author Sam Brannen
31
32
*/
32
33
public class BeanWrapperAutoGrowingTests {
33
34
@@ -66,11 +67,6 @@ public void getPropertyValueAutoGrowArray() {
66
67
assertThat (bean .getArray ()[0 ]).isInstanceOf (Bean .class );
67
68
}
68
69
69
- private void assertNotNull (Object propertyValue ) {
70
- assertThat (propertyValue ).isNotNull ();
71
- }
72
-
73
-
74
70
@ Test
75
71
public void setPropertyValueAutoGrowArray () {
76
72
wrapper .setPropertyValue ("array[0].prop" , "test" );
@@ -93,16 +89,37 @@ public void getPropertyValueAutoGrowArrayBySeveralElements() {
93
89
}
94
90
95
91
@ Test
96
- public void getPropertyValueAutoGrowMultiDimensionalArray () {
92
+ public void getPropertyValueAutoGrow2dArray () {
97
93
assertNotNull (wrapper .getPropertyValue ("multiArray[0][0]" ));
98
94
assertThat (bean .getMultiArray ()[0 ].length ).isEqualTo (1 );
99
95
assertThat (bean .getMultiArray ()[0 ][0 ]).isInstanceOf (Bean .class );
100
96
}
101
97
102
98
@ Test
103
- public void setPropertyValueAutoGrowMultiDimensionalArray () {
104
- wrapper .setPropertyValue ("multiArray[2][3]" , new Bean ());
105
- assertThat (bean .getMultiArray ()[2 ][3 ]).isInstanceOf (Bean .class );
99
+ public void getPropertyValueAutoGrow3dArray () {
100
+ assertNotNull (wrapper .getPropertyValue ("threeDimensionalArray[1][2][3]" ));
101
+ assertThat (bean .getThreeDimensionalArray ()[1 ].length ).isEqualTo (3 );
102
+ assertThat (bean .getThreeDimensionalArray ()[1 ][2 ][3 ]).isInstanceOf (Bean .class );
103
+ }
104
+
105
+ @ Test
106
+ public void setPropertyValueAutoGrow2dArray () {
107
+ Bean newBean = new Bean ();
108
+ newBean .setProp ("enigma" );
109
+ wrapper .setPropertyValue ("multiArray[2][3]" , newBean );
110
+ assertThat (bean .getMultiArray ()[2 ][3 ])
111
+ .isInstanceOf (Bean .class )
112
+ .extracting (Bean ::getProp ).isEqualTo ("enigma" );
113
+ }
114
+
115
+ @ Test
116
+ public void setPropertyValueAutoGrow3dArray () {
117
+ Bean newBean = new Bean ();
118
+ newBean .setProp ("enigma" );
119
+ wrapper .setPropertyValue ("threeDimensionalArray[2][3][4]" , newBean );
120
+ assertThat (bean .getThreeDimensionalArray ()[2 ][3 ][4 ])
121
+ .isInstanceOf (Bean .class )
122
+ .extracting (Bean ::getProp ).isEqualTo ("enigma" );
106
123
}
107
124
108
125
@ Test
@@ -137,7 +154,7 @@ public void getPropertyValueAutoGrowListBySeveralElements() {
137
154
public void getPropertyValueAutoGrowListFailsAgainstLimit () {
138
155
wrapper .setAutoGrowCollectionLimit (2 );
139
156
assertThatExceptionOfType (InvalidPropertyException .class ).isThrownBy (() ->
140
- assertNotNull ( wrapper .getPropertyValue ("list[4]" ) ))
157
+ wrapper .getPropertyValue ("list[4]" ))
141
158
.withRootCauseInstanceOf (IndexOutOfBoundsException .class );
142
159
}
143
160
@@ -167,6 +184,11 @@ public void setNestedPropertyValueAutoGrowMap() {
167
184
}
168
185
169
186
187
+ private static void assertNotNull (Object propertyValue ) {
188
+ assertThat (propertyValue ).isNotNull ();
189
+ }
190
+
191
+
170
192
@ SuppressWarnings ("rawtypes" )
171
193
public static class Bean {
172
194
@@ -180,6 +202,8 @@ public static class Bean {
180
202
181
203
private Bean [][] multiArray ;
182
204
205
+ private Bean [][][] threeDimensionalArray ;
206
+
183
207
private List <Bean > list ;
184
208
185
209
private List <List <Bean >> multiList ;
@@ -220,6 +244,14 @@ public void setMultiArray(Bean[][] multiArray) {
220
244
this .multiArray = multiArray ;
221
245
}
222
246
247
+ public Bean [][][] getThreeDimensionalArray () {
248
+ return threeDimensionalArray ;
249
+ }
250
+
251
+ public void setThreeDimensionalArray (Bean [][][] threeDimensionalArray ) {
252
+ this .threeDimensionalArray = threeDimensionalArray ;
253
+ }
254
+
223
255
public List <Bean > getList () {
224
256
return list ;
225
257
}
0 commit comments