001package org.apache.commons.beanutils2; 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.BeanUtils.on; 023import static org.junit.Assert.assertNotNull; 024 025import org.apache.commons.beanutils2.testbeans.TestBean; 026import org.junit.Test; 027 028public class BeanUtilsTest 029{ 030 031 private static final byte BYTE = 6; 032 033 private static final short SHOT = 45; 034 035 private static final int INT = 329; 036 037 private static final long LONG = 451268l; 038 039 private static final float FLOAT = 47.11f; 040 041 private static final double DOUBLE = 0.4e12d; 042 043 private static final char CHAR = 'X'; 044 045 private static final String STRING = "Hello World!"; 046 047 @Test 048 public void onBeanBooleanPrimitive() 049 { 050 assertNotNull( on( true ) ); 051 } 052 053 @Test 054 public void onBeanBooleanWrapper() 055 { 056 assertNotNull( on( new Boolean( true ) ) ); 057 } 058 059 @Test 060 public void onBeanBytePrimtive() 061 { 062 assertNotNull( on( BYTE ) ); 063 } 064 065 @Test 066 public void onBeanByteWrapper() 067 { 068 assertNotNull( on( new Byte( BYTE ) ) ); 069 } 070 071 @Test 072 public void onBeanShortPrimitive() 073 { 074 assertNotNull( on( SHOT ) ); 075 } 076 077 @Test 078 public void onBeanShortWrapper() 079 { 080 assertNotNull( on( new Short( SHOT ) ) ); 081 } 082 083 @Test 084 public void onBeanIntPrimitive() 085 { 086 assertNotNull( on( INT ) ); 087 } 088 089 @Test 090 public void onBeanIntegerWrapper() 091 { 092 assertNotNull( on( new Integer( INT ) ) ); 093 } 094 095 @Test 096 public void onBeanLongPrimitive() 097 { 098 assertNotNull( on( LONG ) ); 099 } 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}