View Javadoc
1   package org.apache.commons.beanutils2.issues;
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.apache.commons.beanutils2.Argument.argument;
23  import static org.apache.commons.beanutils2.BeanUtils.on;
24  
25  import org.apache.commons.beanutils2.testbeans.TestBean;
26  import org.junit.After;
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  /**
31   * Setting properties or invoking methods to often results in a NullPointerException
32   */
33  public class JiraSandbox433TestCase
34  {
35  
36      private final static int COUNT = 50000;
37  
38      private TestBean testBean;
39  
40      @Before
41      public void setUp()
42      {
43          testBean = new TestBean();
44      }
45  
46      @After
47      public void tearDown()
48      {
49          testBean = null;
50      }
51  
52      @Test
53      public void setPropertyVeryOften()
54      {
55          for ( int i = 0; i < COUNT; i++ )
56          {
57              on( testBean ).set( "intProperty" ).with( i );
58          }
59      }
60  
61      @Test
62      public void getPropertyVeryOften()
63      {
64          for ( int i = 0; i < COUNT; i++ )
65          {
66              on( testBean ).get( "intProperty" );
67          }
68      }
69  
70      @Test
71      public void callMethodVeryOften()
72      {
73          for ( int i = 0; i < COUNT; i++ )
74          {
75              on( testBean ).invoke( "setIntProperty" ).with( argument( i ) );
76          }
77      }
78  
79      @Test
80      public void callConstructorVeryOften()
81      {
82          for ( int i = 0; i < COUNT; i++ )
83          {
84              on( TestBean.class ).newInstance();
85          }
86      }
87  }