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 junit.framework.Test;
20  import junit.framework.TestCase;
21  import junit.framework.TestSuite;
22  
23  import org.apache.commons.beanutils.PropertyUtils;
24  import org.apache.commons.beanutils.TestBean;
25  
26  /**
27   * @version $Id$
28   * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-358">https://issues.apache.org/jira/browse/BEANUTILS-358</a>
29   */
30  public class Jira358TestCase extends TestCase {
31  
32      /**
33       * Create a test case with the specified name.
34       *
35       * @param name The name of the test
36       */
37      public Jira358TestCase(final String name) {
38          super(name);
39      }
40  
41      /**
42       * Run the Test.
43       *
44       * @param args Arguments
45       */
46      public static void main(final String[] args) {
47          junit.textui.TestRunner.run(suite());
48      }
49  
50      /**
51       * Create a test suite for this test.
52       *
53       * @return a test suite
54       */
55      public static Test suite() {
56          return (new TestSuite(Jira358TestCase.class));
57      }
58  
59      /**
60       * Set up.
61       *
62       * @throws java.lang.Exception
63       */
64      @Override
65      protected void setUp() throws Exception {
66          super.setUp();
67      }
68  
69      /**
70       * Tear Down.
71       *
72       * @throws java.lang.Exception
73       */
74      @Override
75      protected void tearDown() throws Exception {
76          super.tearDown();
77      }
78  
79      /**
80       * Test {@link PropertyUtils#getIndexedProperty(Object, String, int)}
81       */
82      public void testPropertyUtils_getIndexedProperty_Array() throws Exception {
83  
84          final TestBean bean = new TestBean();
85          try {
86              PropertyUtils.getIndexedProperty(bean, "intArray", bean.getIntArray().length);
87              fail("Expected ArrayIndexOutOfBoundsException");
88          } catch (final ArrayIndexOutOfBoundsException e) {
89              // expected result
90          }
91      }
92  
93      /**
94       * Test {@link PropertyUtils#getIndexedProperty(Object, String, int)}
95       */
96      public void testPropertyUtils_getIndexedProperty_List() throws Exception {
97  
98          final TestBean bean = new TestBean();
99          try {
100             PropertyUtils.getIndexedProperty(bean, "listIndexed", bean.getListIndexed().size());
101             fail("Expected IndexOutOfBoundsException");
102         } catch (final IndexOutOfBoundsException e) {
103             // expected result
104         }
105     }
106 }