1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.beanutils2.bugs;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20
21 import org.apache.commons.beanutils2.BeanUtils;
22 import org.junit.jupiter.api.AfterEach;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25
26 /**
27 * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-345">https://issues.apache.org/jira/browse/BEANUTILS-345</a>
28 */
29 public class Jira345Test {
30
31 /** Example Bean */
32 public static class MyBean {
33
34 private String[][] matr = { { "1", "2" }, { "3", "4" } };
35
36 private String[][][] matr3D = { { { "11", "12" }, { "13", "14" } }, { { "21", "22" }, { "23", "24" } }, };
37
38 public String[][] getMatr() {
39 return matr;
40 }
41
42 public String[][][] getMatr3D() {
43 return matr3D;
44 }
45
46 public void setMatr(final String[][] matr) {
47 this.matr = matr;
48 }
49
50 public void setMatr3D(final String[][][] matr3D) {
51 this.matr3D = matr3D;
52 }
53 }
54
55 /**
56 * Sets up.
57 *
58 * @throws Exception
59 */
60 @BeforeEach
61 protected void setUp() throws Exception {
62 }
63
64 /**
65 * Tear Down.
66 *
67 * @throws Exception
68 */
69 @AfterEach
70 protected void tearDown() throws Exception {
71 }
72
73 /**
74 * Test {@link BeanUtils} setProperty() with 2D array.
75 */
76 @Test
77 public void testBeanUtilsSetProperty_2DArray() throws Exception {
78 final MyBean myBean = new MyBean();
79 BeanUtils.setProperty(myBean, "matr[0][0]", "Sample");
80 assertEquals("Sample", myBean.getMatr()[0][0]);
81 }
82
83 /**
84 * Test {@link BeanUtils} setProperty() with 3D array.
85 */
86 @Test
87 public void testBeanUtilsSetProperty_3DArray() throws Exception {
88 final MyBean myBean = new MyBean();
89 BeanUtils.setProperty(myBean, "matr3D[0][0][0]", "Sample");
90 assertEquals("Sample", myBean.getMatr3D()[0][0][0]);
91 }
92 }