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    *      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 java.lang.reflect.Method;
22  
23  import org.apache.commons.beanutils2.MethodUtils;
24  import org.apache.commons.beanutils2.PropertyUtils;
25  import org.apache.commons.beanutils2.bugs.other.Jira298BeanFactory;
26  import org.apache.commons.beanutils2.bugs.other.Jira298BeanFactory.IX;
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.junit.jupiter.api.AfterEach;
30  import org.junit.jupiter.api.BeforeEach;
31  import org.junit.jupiter.api.Test;
32  
33  /**
34   * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-298">https://issues.apache.org/jira/browse/BEANUTILS-298</a>
35   */
36  public class Jira298Test {
37  
38      private static final Log LOG = LogFactory.getLog(Jira298Test.class);
39  
40      /**
41       * Sets up.
42       *
43       * @throws Exception
44       */
45      @BeforeEach
46      protected void setUp() throws Exception {
47      }
48  
49      /**
50       * Tear Down.
51       *
52       * @throws Exception
53       */
54      @AfterEach
55      protected void tearDown() throws Exception {
56      }
57  
58      /**
59       * Test {@link MethodUtils#getAccessibleMethod(Class, Method)}
60       */
61      @Test
62      public void testIssue_BEANUTILS_298_MethodUtils_getAccessibleMethod() throws Exception {
63          final Object bean = Jira298BeanFactory.createImplX();
64          Object result = null;
65          final Method m2 = MethodUtils.getAccessibleMethod(bean.getClass(), "getName", new Class[0]);
66          result = m2.invoke(bean);
67          assertEquals("BaseX name value", result);
68      }
69  
70      /**
71       * Test {@link PropertyUtils#getProperty(Object, String)}
72       */
73      @Test
74      public void testIssue_BEANUTILS_298_PropertyUtils_getProperty() throws Exception {
75          final Object bean = Jira298BeanFactory.createImplX();
76          final Object result = PropertyUtils.getProperty(bean, "name");
77          assertEquals("BaseX name value", result);
78      }
79  
80      /**
81       * Test {@link PropertyUtils#setProperty(Object, String, Object)}
82       */
83      @Test
84      public void testIssue_BEANUTILS_298_PropertyUtils_setProperty() throws Exception {
85          final Object bean = Jira298BeanFactory.createImplX();
86          assertEquals("BaseX name value", ((IX) bean).getName());
87          PropertyUtils.setProperty(bean, "name", "new name");
88          assertEquals("new name", ((IX) bean).getName());
89      }
90  }