View Javadoc
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    *      http://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.beanutils.bugs;
18  
19  import static org.junit.Assert.assertEquals;
20  
21  import org.apache.commons.beanutils.PropertyUtils;
22  import org.junit.Test;
23  
24  /**
25   * Variant of {@link Jira422TestCase} that is compatible with BEANUTILS-492
26   *
27   * @version $Id$
28   * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-422">BEANUTILS-422</a>
29   * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-492">BEANUTILS-492</a>
30   */
31  public class Jira422bTestCase {
32  
33      @Test
34      public void testRootBean() throws Exception {
35          final RootBeanB bean = new FirstChildBeanB();
36          final Class<?> propertyType = PropertyUtils.getPropertyType(bean, "file[0]");
37          assertEquals(String.class.getName(), propertyType.getName());
38      }
39  
40  
41      @Test
42      public void testSecondChildBean() throws Exception {
43          final RootBeanB bean = new SecondChildBeanB();
44          final Class<?> propertyType = PropertyUtils.getPropertyType(bean, "file[0]");
45          assertEquals(String.class.getName(), propertyType.getName());
46      }
47  
48  }
49  
50  
51  class RootBeanB {
52  
53      private String[] file;
54  
55      public String[] getFile() {
56          return file;
57      }
58  
59      public void setFile(final String[] file) {
60          this.file = file;
61      }
62  
63      public String getFile(final int i) {
64          return file[i];
65      }
66  
67      public void setFile(final int i, final String file) {
68          this.file[i] = file;
69      }
70  
71  }
72  
73  class FirstChildBeanB extends RootBeanB {
74  }
75  
76  class SecondChildBeanB extends RootBeanB {
77  }