View Javadoc
1   package org.apache.commons.beanutils2;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.assertFalse;
23  import static org.junit.Assert.assertTrue;
24  
25  import java.lang.reflect.Method;
26  
27  import org.apache.commons.beanutils2.testbeans.TestBean;
28  import org.junit.Test;
29  
30  public class MethodUtilsTest
31  {
32  
33      @Test
34      public void isMappedSetterWithMappedPropertySetter()
35          throws Exception
36      {
37          Method mappedPropertySetter =
38              TestBean.class.getMethod( "setMappedProperty", new Class<?>[] { String.class, String.class } );
39          assertTrue( MethodUtils.isMappedSetter( mappedPropertySetter ) );
40      }
41  
42      @Test
43      public void isMappedSetterWithIndexedPropertySetter()
44          throws Exception
45      {
46          Method indexedPropertySetter =
47              TestBean.class.getMethod( "setIntIndexed", new Class<?>[] { int.class, int.class } );
48          assertFalse( MethodUtils.isMappedSetter( indexedPropertySetter ) );
49      }
50  
51      @Test
52      public void isMappedSetterWithStringPropertySetter()
53          throws Exception
54      {
55  
56          Method stringPropertySetter = TestBean.class.getMethod( "setStringProperty", new Class<?>[] { String.class } );
57          assertFalse( MethodUtils.isMappedSetter( stringPropertySetter ) );
58      }
59  
60      @Test
61      public void isMappedGetterWithMappedPropertyGetter()
62          throws Exception
63      {
64          Method mappedPropertyGetter = TestBean.class.getMethod( "getMappedProperty", new Class<?>[] { String.class } );
65          assertTrue( MethodUtils.isMappedGetter( mappedPropertyGetter ) );
66      }
67  
68      @Test
69      public void isMappedGetterWithIndexedPropertyGetter()
70          throws Exception
71      {
72          Method indexedPropertyGetter = TestBean.class.getMethod( "getIntIndexed", new Class<?>[] { int.class } );
73          assertFalse( MethodUtils.isMappedGetter( indexedPropertyGetter ) );
74      }
75  
76      @Test
77      public void isMappedGetterWithStringPropertyGetter()
78          throws Exception
79      {
80  
81          Method stringPropertyGetter = TestBean.class.getMethod( "getStringProperty", new Class<?>[] {} );
82          assertFalse( MethodUtils.isMappedGetter( stringPropertyGetter ) );
83      }
84  
85  }