001package org.apache.commons.beanutils2;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.junit.Assert.assertFalse;
023import static org.junit.Assert.assertTrue;
024
025import java.lang.reflect.Method;
026
027import org.apache.commons.beanutils2.testbeans.TestBean;
028import org.junit.Test;
029
030public class MethodUtilsTest
031{
032
033    @Test
034    public void isMappedSetterWithMappedPropertySetter()
035        throws Exception
036    {
037        Method mappedPropertySetter =
038            TestBean.class.getMethod( "setMappedProperty", new Class<?>[] { String.class, String.class } );
039        assertTrue( MethodUtils.isMappedSetter( mappedPropertySetter ) );
040    }
041
042    @Test
043    public void isMappedSetterWithIndexedPropertySetter()
044        throws Exception
045    {
046        Method indexedPropertySetter =
047            TestBean.class.getMethod( "setIntIndexed", new Class<?>[] { int.class, int.class } );
048        assertFalse( MethodUtils.isMappedSetter( indexedPropertySetter ) );
049    }
050
051    @Test
052    public void isMappedSetterWithStringPropertySetter()
053        throws Exception
054    {
055
056        Method stringPropertySetter = TestBean.class.getMethod( "setStringProperty", new Class<?>[] { String.class } );
057        assertFalse( MethodUtils.isMappedSetter( stringPropertySetter ) );
058    }
059
060    @Test
061    public void isMappedGetterWithMappedPropertyGetter()
062        throws Exception
063    {
064        Method mappedPropertyGetter = TestBean.class.getMethod( "getMappedProperty", new Class<?>[] { String.class } );
065        assertTrue( MethodUtils.isMappedGetter( mappedPropertyGetter ) );
066    }
067
068    @Test
069    public void isMappedGetterWithIndexedPropertyGetter()
070        throws Exception
071    {
072        Method indexedPropertyGetter = TestBean.class.getMethod( "getIntIndexed", new Class<?>[] { int.class } );
073        assertFalse( MethodUtils.isMappedGetter( indexedPropertyGetter ) );
074    }
075
076    @Test
077    public void isMappedGetterWithStringPropertyGetter()
078        throws Exception
079    {
080
081        Method stringPropertyGetter = TestBean.class.getMethod( "getStringProperty", new Class<?>[] {} );
082        assertFalse( MethodUtils.isMappedGetter( stringPropertyGetter ) );
083    }
084
085}