001package org.apache.commons.beanutils2;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements.  See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020import static org.apache.commons.beanutils2.BeanUtils.on;
021import static org.junit.Assert.assertFalse;
022import static org.junit.Assert.assertTrue;
023
024import org.apache.commons.beanutils2.testbeans.TestBean;
025import org.junit.Test;
026
027public class IsWritableTestCase
028{
029
030    @Test( expected = NullPointerException.class )
031    public void isWritableNull()
032        throws Exception
033    {
034        on( TestBean.class ).getProperties().isWritable( null );
035    }
036
037    @Test( expected = NoSuchPropertyException.class )
038    public void isWritbleUnknown()
039        throws Exception
040    {
041        on( TestBean.class ).getProperties().isWritable( "unknown" );
042    }
043
044    @Test
045    public void isWritbleIntProperty()
046        throws Exception
047    {
048        assertTrue( "isWritable returned false for a read/write int property!",
049                    on( TestBean.class ).getProperties().isWritable( "intProperty" ) );
050    }
051
052    @Test
053    public void isWritbleIntArray()
054        throws Exception
055    {
056        assertTrue( "isWritable returned false for a read/write array property!",
057                    on( TestBean.class ).getProperties().isWritable( "intArray" ) );
058    }
059
060    @Test
061    public void isWritableIntIndexed()
062        throws Exception
063    {
064        assertTrue( "isWritable returned false for a read/write indexed property!",
065                    on( TestBean.class ).getProperties().isWritable( "intIndexed" ) );
066    }
067
068    @Test
069    public void isWritableMappedIntProperty()
070        throws Exception
071    {
072        assertTrue( "isWritable returned false for a read/write mapped property!",
073                    on( TestBean.class ).getProperties().isWritable( "mappedIntProperty" ) );
074    }
075
076    @Test
077    public void isWritbleMapProperty()
078        throws Exception
079    {
080        assertTrue( "isWritable returned false for a read/write map property!",
081                    on( TestBean.class ).getProperties().isWritable( "mapProperty" ) );
082    }
083
084    @Test
085    public void isWritableReadOnlyProperty()
086        throws Exception
087    {
088        assertFalse( "isWriteable returned true for a read only property!",
089                     on( TestBean.class ).getProperties().isWritable( "readOnlyProperty" ) );
090    }
091
092    @Test
093    public void isWritableWriteOnlyProperty()
094        throws Exception
095    {
096        assertTrue( "isWritable returned false for a write only property!",
097                    on( TestBean.class ).getProperties().isWritable( "writeOnlyProperty" ) );
098    }
099
100}