Skip to content

Commit

Permalink
Polish contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Feb 25, 2021
1 parent a33eac3 commit 8baf404
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@
/**
* @author Keith Donald
* @author Juergen Hoeller
* @author Sam Brannen
*/
public class BeanWrapperAutoGrowingTests {

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

private void assertNotNull(Object propertyValue) {
assertThat(propertyValue).isNotNull();
}


@Test
public void setPropertyValueAutoGrowArray() {
wrapper.setPropertyValue("array[0].prop", "test");
Expand All @@ -93,16 +89,37 @@ public void getPropertyValueAutoGrowArrayBySeveralElements() {
}

@Test
public void getPropertyValueAutoGrowMultiDimensionalArray() {
public void getPropertyValueAutoGrow2dArray() {
assertNotNull(wrapper.getPropertyValue("multiArray[0][0]"));
assertThat(bean.getMultiArray()[0].length).isEqualTo(1);
assertThat(bean.getMultiArray()[0][0]).isInstanceOf(Bean.class);
}

@Test
public void setPropertyValueAutoGrowMultiDimensionalArray() {
wrapper.setPropertyValue("multiArray[2][3]", new Bean());
assertThat(bean.getMultiArray()[2][3]).isInstanceOf(Bean.class);
public void getPropertyValueAutoGrow3dArray() {
assertNotNull(wrapper.getPropertyValue("threeDimensionalArray[1][2][3]"));
assertThat(bean.getThreeDimensionalArray()[1].length).isEqualTo(3);
assertThat(bean.getThreeDimensionalArray()[1][2][3]).isInstanceOf(Bean.class);
}

@Test
public void setPropertyValueAutoGrow2dArray() {
Bean newBean = new Bean();
newBean.setProp("enigma");
wrapper.setPropertyValue("multiArray[2][3]", newBean);
assertThat(bean.getMultiArray()[2][3])
.isInstanceOf(Bean.class)
.extracting(Bean::getProp).isEqualTo("enigma");
}

@Test
public void setPropertyValueAutoGrow3dArray() {
Bean newBean = new Bean();
newBean.setProp("enigma");
wrapper.setPropertyValue("threeDimensionalArray[2][3][4]", newBean);
assertThat(bean.getThreeDimensionalArray()[2][3][4])
.isInstanceOf(Bean.class)
.extracting(Bean::getProp).isEqualTo("enigma");
}

@Test
Expand Down Expand Up @@ -137,7 +154,7 @@ public void getPropertyValueAutoGrowListBySeveralElements() {
public void getPropertyValueAutoGrowListFailsAgainstLimit() {
wrapper.setAutoGrowCollectionLimit(2);
assertThatExceptionOfType(InvalidPropertyException.class).isThrownBy(() ->
assertNotNull(wrapper.getPropertyValue("list[4]")))
wrapper.getPropertyValue("list[4]"))
.withRootCauseInstanceOf(IndexOutOfBoundsException.class);
}

Expand Down Expand Up @@ -167,6 +184,11 @@ public void setNestedPropertyValueAutoGrowMap() {
}


private static void assertNotNull(Object propertyValue) {
assertThat(propertyValue).isNotNull();
}


@SuppressWarnings("rawtypes")
public static class Bean {

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

private Bean[][] multiArray;

private Bean[][][] threeDimensionalArray;

private List<Bean> list;

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

public Bean[][][] getThreeDimensionalArray() {
return threeDimensionalArray;
}

public void setThreeDimensionalArray(Bean[][][] threeDimensionalArray) {
this.threeDimensionalArray = threeDimensionalArray;
}

public List<Bean> getList() {
return list;
}
Expand Down

0 comments on commit 8baf404

Please sign in to comment.