Skip to content

Commit 8baf404

Browse files
committed
Polish contribution
See gh-26600
1 parent a33eac3 commit 8baf404

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
/**
2929
* @author Keith Donald
3030
* @author Juergen Hoeller
31+
* @author Sam Brannen
3132
*/
3233
public class BeanWrapperAutoGrowingTests {
3334

@@ -66,11 +67,6 @@ public void getPropertyValueAutoGrowArray() {
6667
assertThat(bean.getArray()[0]).isInstanceOf(Bean.class);
6768
}
6869

69-
private void assertNotNull(Object propertyValue) {
70-
assertThat(propertyValue).isNotNull();
71-
}
72-
73-
7470
@Test
7571
public void setPropertyValueAutoGrowArray() {
7672
wrapper.setPropertyValue("array[0].prop", "test");
@@ -93,16 +89,37 @@ public void getPropertyValueAutoGrowArrayBySeveralElements() {
9389
}
9490

9591
@Test
96-
public void getPropertyValueAutoGrowMultiDimensionalArray() {
92+
public void getPropertyValueAutoGrow2dArray() {
9793
assertNotNull(wrapper.getPropertyValue("multiArray[0][0]"));
9894
assertThat(bean.getMultiArray()[0].length).isEqualTo(1);
9995
assertThat(bean.getMultiArray()[0][0]).isInstanceOf(Bean.class);
10096
}
10197

10298
@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");
106123
}
107124

108125
@Test
@@ -137,7 +154,7 @@ public void getPropertyValueAutoGrowListBySeveralElements() {
137154
public void getPropertyValueAutoGrowListFailsAgainstLimit() {
138155
wrapper.setAutoGrowCollectionLimit(2);
139156
assertThatExceptionOfType(InvalidPropertyException.class).isThrownBy(() ->
140-
assertNotNull(wrapper.getPropertyValue("list[4]")))
157+
wrapper.getPropertyValue("list[4]"))
141158
.withRootCauseInstanceOf(IndexOutOfBoundsException.class);
142159
}
143160

@@ -167,6 +184,11 @@ public void setNestedPropertyValueAutoGrowMap() {
167184
}
168185

169186

187+
private static void assertNotNull(Object propertyValue) {
188+
assertThat(propertyValue).isNotNull();
189+
}
190+
191+
170192
@SuppressWarnings("rawtypes")
171193
public static class Bean {
172194

@@ -180,6 +202,8 @@ public static class Bean {
180202

181203
private Bean[][] multiArray;
182204

205+
private Bean[][][] threeDimensionalArray;
206+
183207
private List<Bean> list;
184208

185209
private List<List<Bean>> multiList;
@@ -220,6 +244,14 @@ public void setMultiArray(Bean[][] multiArray) {
220244
this.multiArray = multiArray;
221245
}
222246

247+
public Bean[][][] getThreeDimensionalArray() {
248+
return threeDimensionalArray;
249+
}
250+
251+
public void setThreeDimensionalArray(Bean[][][] threeDimensionalArray) {
252+
this.threeDimensionalArray = threeDimensionalArray;
253+
}
254+
223255
public List<Bean> getList() {
224256
return list;
225257
}

0 commit comments

Comments
 (0)