001package org.apache.commons.beanutils2.issues;
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.apache.commons.beanutils2.Argument.argument;
023import static org.apache.commons.beanutils2.BeanUtils.on;
024
025import org.apache.commons.beanutils2.testbeans.TestBean;
026import org.junit.After;
027import org.junit.Before;
028import org.junit.Test;
029
030/**
031 * Setting properties or invoking methods to often results in a NullPointerException
032 */
033public class JiraSandbox433TestCase
034{
035
036    private final static int COUNT = 50000;
037
038    private TestBean testBean;
039
040    @Before
041    public void setUp()
042    {
043        testBean = new TestBean();
044    }
045
046    @After
047    public void tearDown()
048    {
049        testBean = null;
050    }
051
052    @Test
053    public void setPropertyVeryOften()
054    {
055        for ( int i = 0; i < COUNT; i++ )
056        {
057            on( testBean ).set( "intProperty" ).with( i );
058        }
059    }
060
061    @Test
062    public void getPropertyVeryOften()
063    {
064        for ( int i = 0; i < COUNT; i++ )
065        {
066            on( testBean ).get( "intProperty" );
067        }
068    }
069
070    @Test
071    public void callMethodVeryOften()
072    {
073        for ( int i = 0; i < COUNT; i++ )
074        {
075            on( testBean ).invoke( "setIntProperty" ).with( argument( i ) );
076        }
077    }
078
079    @Test
080    public void callConstructorVeryOften()
081    {
082        for ( int i = 0; i < COUNT; i++ )
083        {
084            on( TestBean.class ).newInstance();
085        }
086    }
087}