View Javadoc
1   package org.apache.commons.beanutils2;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import static org.apache.commons.beanutils2.BeanUtils.on;
21  import static org.junit.Assert.assertNull;
22  import static org.junit.Assert.assertTrue;
23  
24  import java.util.HashMap;
25  
26  import org.apache.commons.beanutils2.testbeans.TestBean;
27  import org.junit.After;
28  import org.junit.Before;
29  import org.junit.Test;
30  
31  /**
32   * Test case to make sure, that methods with void signature are handled correctly.
33   */
34  public class VoidMethodsTestCase
35  {
36  
37      private BeanAccessor<?> voidAccessor = null;
38  
39      @Before
40      public void setUp()
41          throws Exception
42      {
43          voidAccessor = on( TestBean.class ).invokeStatic( "incrementCounter" ).with();
44          assertTrue( voidAccessor instanceof NullBeanAccessor );
45      }
46  
47      @After
48      public void tearDown()
49      {
50          voidAccessor = null;
51      }
52  
53      @Test
54      public void get()
55          throws Exception
56      {
57          assertNull( voidAccessor.get() );
58      }
59  
60      @Test( expected = NullPointerException.class )
61      public void getProperty()
62          throws Exception
63      {
64          voidAccessor.get( "propertyName" );
65      }
66  
67      @Test( expected = NullPointerException.class )
68      public void getIndexed()
69          throws Exception
70      {
71          voidAccessor.getIndexed( "propertyName" );
72      }
73  
74      @Test( expected = NullPointerException.class )
75      public void getMapped()
76          throws Exception
77      {
78          voidAccessor.getMapped( "propertyName" );
79      }
80  
81      @Test( expected = NullPointerException.class )
82      public void setProperty()
83          throws Exception
84      {
85          voidAccessor.set( "propertyName" );
86      }
87  
88      @Test( expected = NullPointerException.class )
89      public void setIndexed()
90          throws Exception
91      {
92          voidAccessor.setIndexed( "propertyName" );
93      }
94  
95      @Test( expected = NullPointerException.class )
96      public void setMapped()
97          throws Exception
98      {
99          voidAccessor.setMapped( "propertyName" );
100     }
101 
102     @Test
103     public void cast()
104     {
105         assertNull( voidAccessor.cast() );
106     }
107 
108     @Test
109     public void cloneBean()
110         throws Exception
111     {
112         assertNull( voidAccessor.cloneBean() );
113     }
114 
115     @Test( expected = NullPointerException.class )
116     public void describe()
117         throws Exception
118     {
119         voidAccessor.describe();
120     }
121 
122     @Test( expected = NullPointerException.class )
123     public void populate()
124         throws Exception
125     {
126         voidAccessor.populate( new HashMap<String, Object>( 0 ) );
127     }
128 
129     @Test
130     public void copyPropertiesTo()
131         throws Exception
132     {
133         // no idea how to invoke this
134         // voidAccessor.copyPropertiesTo( target );
135     }
136 
137     @Test( expected = NullPointerException.class )
138     public void invoke()
139         throws Exception
140     {
141         voidAccessor.invoke( "methodName" );
142     }
143 
144     @Test( expected = NullPointerException.class )
145     public void invokeExact()
146         throws Exception
147     {
148         voidAccessor.invokeExact( "methodName" );
149     }
150 
151 }