View Javadoc
1   package org.apache.commons.beanutils2;
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.BeanUtils.on;
23  import static org.junit.Assert.assertNotNull;
24  
25  import org.apache.commons.beanutils2.testbeans.TestBean;
26  import org.junit.Test;
27  
28  public class BeanUtilsTest
29  {
30  
31      private static final byte BYTE = 6;
32  
33      private static final short SHOT = 45;
34  
35      private static final int INT = 329;
36  
37      private static final long LONG = 451268l;
38  
39      private static final float FLOAT = 47.11f;
40  
41      private static final double DOUBLE = 0.4e12d;
42  
43      private static final char CHAR = 'X';
44  
45      private static final String STRING = "Hello World!";
46  
47      @Test
48      public void onBeanBooleanPrimitive()
49      {
50          assertNotNull( on( true ) );
51      }
52  
53      @Test
54      public void onBeanBooleanWrapper()
55      {
56          assertNotNull( on( new Boolean( true ) ) );
57      }
58  
59      @Test
60      public void onBeanBytePrimtive()
61      {
62          assertNotNull( on( BYTE ) );
63      }
64  
65      @Test
66      public void onBeanByteWrapper()
67      {
68          assertNotNull( on( new Byte( BYTE ) ) );
69      }
70  
71      @Test
72      public void onBeanShortPrimitive()
73      {
74          assertNotNull( on( SHOT ) );
75      }
76  
77      @Test
78      public void onBeanShortWrapper()
79      {
80          assertNotNull( on( new Short( SHOT ) ) );
81      }
82  
83      @Test
84      public void onBeanIntPrimitive()
85      {
86          assertNotNull( on( INT ) );
87      }
88  
89      @Test
90      public void onBeanIntegerWrapper()
91      {
92          assertNotNull( on( new Integer( INT ) ) );
93      }
94  
95      @Test
96      public void onBeanLongPrimitive()
97      {
98          assertNotNull( on( LONG ) );
99      }
100 
101     @Test
102     public void onBeanLongWrapper()
103     {
104         assertNotNull( on( new Long( LONG ) ) );
105     }
106 
107     @Test
108     public void onBeanFloatPrimitive()
109     {
110         assertNotNull( on( FLOAT ) );
111     }
112 
113     @Test
114     public void onBeanFloatWrapper()
115     {
116         assertNotNull( on( new Float( FLOAT ) ) );
117     }
118 
119     @Test
120     public void onBeanDoublePrimitive()
121     {
122         assertNotNull( on( DOUBLE ) );
123     }
124 
125     @Test
126     public void onBeanDoubleWrapper()
127     {
128         assertNotNull( on( new Double( DOUBLE ) ) );
129     }
130 
131     @Test
132     public void onBeanCharPrimitive()
133     {
134         assertNotNull( on( CHAR ) );
135     }
136 
137     @Test
138     public void onBeanCharacterWrapper()
139     {
140         assertNotNull( on( new Character( CHAR ) ) );
141     }
142 
143     @Test
144     public void onBeanString()
145     {
146         assertNotNull( on( STRING ) );
147     }
148 
149     @Test
150     public void onBeanObject()
151     {
152         assertNotNull( on( new Object() ) );
153     }
154 
155     @Test
156     public void onBeanTestBean()
157     {
158         assertNotNull( on( new TestBean( FLOAT, STRING ) ) );
159     }
160 
161     @Test( expected = NullPointerException.class )
162     public void onBeanNull()
163     {
164         on( (Object) null );
165     }
166 
167     @Test
168     public void onClassBooleanPrimitive()
169     {
170         assertNotNull( on( boolean.class ) );
171     }
172 
173     @Test
174     public void onClassBytePrimitive()
175     {
176         assertNotNull( on( byte.class ) );
177     }
178 
179     @Test
180     public void onClassShortPrimitive()
181     {
182         assertNotNull( on( short.class ) );
183     }
184 
185     @Test
186     public void onClassIntPrimitive()
187     {
188         assertNotNull( on( int.class ) );
189     }
190 
191     @Test
192     public void onClassLongPrimitive()
193     {
194         assertNotNull( on( long.class ) );
195     }
196 
197     @Test
198     public void onClassFloatPrimitive()
199     {
200         assertNotNull( on( float.class ) );
201     }
202 
203     @Test
204     public void onClassDoublePrimitive()
205     {
206         assertNotNull( on( double.class ) );
207     }
208 
209     @Test
210     public void onClassCharPrimitive()
211     {
212         assertNotNull( on( char.class ) );
213     }
214 
215     @Test
216     public void onClassBooleanWrapper()
217     {
218         assertNotNull( on( Boolean.class ) );
219     }
220 
221     @Test
222     public void onClassByteWrapper()
223     {
224         assertNotNull( on( Byte.class ) );
225     }
226 
227     @Test
228     public void onClassShortWrapper()
229     {
230         assertNotNull( on( Short.class ) );
231     }
232 
233     @Test
234     public void onClassIntegerWrapper()
235     {
236         assertNotNull( on( Integer.class ) );
237     }
238 
239     @Test
240     public void onClassLongWrapper()
241     {
242         assertNotNull( on( Long.class ) );
243     }
244 
245     @Test
246     public void onClassFloatWrapper()
247     {
248         assertNotNull( on( Float.class ) );
249     }
250 
251     @Test
252     public void onClassDoubleWrapper()
253     {
254         assertNotNull( on( Double.class ) );
255     }
256 
257     @Test
258     public void onClassWrappers()
259     {
260         assertNotNull( on( Character.class ) );
261     }
262 
263     @Test
264     public void onClassString()
265     {
266         assertNotNull( on( String.class ) );
267     }
268 
269     @Test
270     public void onClassObject()
271     {
272         assertNotNull( on( Object.class ) );
273     }
274 
275     @Test
276     public void onClassTestBean()
277     {
278         assertNotNull( on( TestBean.class ) );
279     }
280 
281     @Test( expected = NullPointerException.class )
282     public void onClassNull()
283     {
284         on( null );
285     }
286 
287 }