Author: simonetripodi Date: Sat Jan 28 10:27:15 2012 New Revision: 1237034 URL: http://svn.apache.org/viewvc?rev=1237034&view=rev Log: [SANDBOX-362] applied patches for BeanUtilsTest and ConstrucotrTestCase, provided by Benedikt Ritter
Added: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/BeanUtilsTest.java (with props) Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java?rev=1237034&r1=1237033&r2=1237034&view=diff ============================================================================== --- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java (original) +++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultClassAccessor.java Sat Jan 28 10:27:15 2012 @@ -100,7 +100,7 @@ final class DefaultClassAccessor<B> if ( null == constructor ) { - throw new NoSuchMethodException( "No such accessible constructor on object: " + beanClass.getName() ); + throw new NoSuchMethodException( "No such accessible constructor on class: " + beanClass.getName() ); } int argumentsLength = arguments.length; Added: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/BeanUtilsTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/BeanUtilsTest.java?rev=1237034&view=auto ============================================================================== --- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/BeanUtilsTest.java (added) +++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/BeanUtilsTest.java Sat Jan 28 10:27:15 2012 @@ -0,0 +1,284 @@ +package org.apache.commons.beanutils2; + +import static org.apache.commons.beanutils2.BeanUtils.on; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class BeanUtilsTest +{ + + private static final byte BYTE = 6; + + private static final short SHOT = 45; + + private static final int INT = 329; + + private static final long LONG = 451268l; + + private static final float FLOAT = 47.11f; + + private static final double DOUBLE = 0.4e12d; + + private static final char CHAR = 'X'; + + private static final String STRING = "Hello World!"; + + @Test + public void onBeanBooleanPrimitive() + { + assertNotNull( on( true ) ); + } + + @Test + public void onBeanBooleanWrapper() + { + assertNotNull( on( new Boolean( true ) ) ); + } + + @Test + public void onBeanBytePrimtive() + { + assertNotNull( on( BYTE ) ); + } + + @Test + public void onBeanByteWrapper() + { + assertNotNull( on( new Byte( BYTE ) ) ); + } + + @Test + public void onBeanShortPrimitive() + { + assertNotNull( on( SHOT ) ); + } + + @Test + public void onBeanShortWrapper() + { + assertNotNull( on( new Short( SHOT ) ) ); + } + + @Test + public void onBeanIntPrimitive() + { + assertNotNull( on( INT ) ); + } + + @Test + public void onBeanIntegerWrapper() + { + assertNotNull( on( new Integer( INT ) ) ); + } + + @Test + public void onBeanLongPrimitive() + { + assertNotNull( on( LONG ) ); + } + + @Test + public void onBeanLongWrapper() + { + assertNotNull( on( new Long( LONG ) ) ); + } + + @Test + public void onBeanFloatPrimitive() + { + assertNotNull( on( FLOAT ) ); + } + + @Test + public void onBeanFloatWrapper() + { + assertNotNull( on( new Float( FLOAT ) ) ); + } + + @Test + public void onBeanDoublePrimitive() + { + assertNotNull( on( DOUBLE ) ); + } + + @Test + public void onBeanDoubleWrapper() + { + assertNotNull( on( new Double( DOUBLE ) ) ); + } + + @Test + public void onBeanCharPrimitive() + { + assertNotNull( on( CHAR ) ); + } + + @Test + public void onBeanCharacterWrapper() + { + assertNotNull( on( new Character( CHAR ) ) ); + } + + @Test + public void onBeanString() + { + assertNotNull( on( STRING ) ); + } + + @Test + public void onBeanObject() + { + assertNotNull( on( new Object() ) ); + } + + @Test + public void onBeanTestBean() + { + assertNotNull( on( new TestBean( FLOAT, STRING ) ) ); + } + + @Test( expected = NullPointerException.class ) + public void onBeanNull() + { + on( (Object) null ); + } + + @Test + public void onClassBooleanPrimitive() + { + assertNotNull( on( boolean.class ) ); + } + + @Test + public void onClassBytePrimitive() + { + assertNotNull( on( byte.class ) ); + } + + @Test + public void onClassShortPrimitive() + { + assertNotNull( on( short.class ) ); + } + + @Test + public void onClassIntPrimitive() + { + assertNotNull( on( int.class ) ); + } + + @Test + public void onClassLongPrimitive() + { + assertNotNull( on( long.class ) ); + } + + @Test + public void onClassFloatPrimitive() + { + assertNotNull( on( float.class ) ); + } + + @Test + public void onClassDoublePrimitive() + { + assertNotNull( on( double.class ) ); + } + + @Test + public void onClassCharPrimitive() + { + assertNotNull( on( char.class ) ); + } + + @Test + public void onClassBooleanWrapper() + { + assertNotNull( on( Boolean.class ) ); + } + + @Test + public void onClassByteWrapper() + { + assertNotNull( on( Byte.class ) ); + } + + @Test + public void onClassShortWrapper() + { + assertNotNull( on( Short.class ) ); + } + + @Test + public void onClassIntegerWrapper() + { + assertNotNull( on( Integer.class ) ); + } + + @Test + public void onClassLongWrapper() + { + assertNotNull( on( Long.class ) ); + } + + @Test + public void onClassFloatWrapper() + { + assertNotNull( on( Float.class ) ); + } + + @Test + public void onClassDoubleWrapper() + { + assertNotNull( on( Double.class ) ); + } + + @Test + public void onClassWrappers() + { + assertNotNull( on( Character.class ) ); + } + + @Test + public void onClassString() + { + assertNotNull( on( String.class ) ); + } + + @Test + public void onClassObject() + { + assertNotNull( on( Object.class ) ); + } + + @Test + public void onClassTestBean() + { + assertNotNull( on( TestBean.class ) ); + } + + @Test( expected = NullPointerException.class ) + public void onClassNull() + { + on( null ); + } + +} Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/BeanUtilsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/BeanUtilsTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/BeanUtilsTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java?rev=1237034&r1=1237033&r2=1237034&view=diff ============================================================================== --- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java (original) +++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ConstructorsTestCase.java Sat Jan 28 10:27:15 2012 @@ -21,9 +21,10 @@ import static org.apache.commons.beanuti import static org.apache.commons.beanutils2.BeanUtils.on; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; /** * <p> @@ -32,6 +33,8 @@ import org.junit.Test; */ public class ConstructorsTestCase { + @Rule + public ExpectedException thrown = ExpectedException.none(); // ------------------------------------------------ Individual Test Methods @@ -52,6 +55,23 @@ public class ConstructorsTestCase } @Test + public void invokeConstructorWithInvalidArgument() + throws Exception + { + thrown.expect( NoSuchMethodException.class ); + thrown.expectMessage( "No such accessible constructor on class:" ); + thrown.expectMessage( TestBean.class.getName() ); + on( TestBean.class ).invokeConstructor( argument( (byte) 6 ) ).get(); + } + + @Test( expected = NullPointerException.class ) + public void invokeConstructorWithNull() + throws Exception + { + on( TestBean.class ).invokeConstructor( (Argument<?>) null ); + } + + @Test public void invokeConstructorWithArgArray() throws Exception { @@ -62,6 +82,23 @@ public class ConstructorsTestCase } @Test + public void invokeConstrucotrWithInvalidArgArray() + throws Exception + { + thrown.expect( NoSuchMethodException.class ); + thrown.expectMessage( "No such accessible constructor on class:" ); + thrown.expectMessage( TestBean.class.getName() ); + on( TestBean.class ).invokeConstructor( argument( (byte) 17 ), argument( "TEST" ) ).get(); + } + + @Test( expected = NullPointerException.class ) + public void invokeConstructorWithNullArray() + throws Exception + { + on( TestBean.class ).invokeConstructor( null, null, null ); + } + + @Test public void invokeConstructorWithTypeArray() throws Exception { @@ -82,6 +119,16 @@ public class ConstructorsTestCase } @Test + public void invokeConstructorWithInvalidTypeArray() throws Exception + { + thrown.expect( NoSuchMethodException.class ); + thrown.expectMessage( "No such accessible constructor on class:" ); + thrown.expectMessage( TestBean.class.getName() ); + on( TestBean.class ).invokeConstructor( argument( String.class, "TEST" ), + argument( Boolean.TYPE, Boolean.TRUE )).get(); + } + + @Test public void invokeExactConstructor() throws Exception { @@ -91,17 +138,6 @@ public class ConstructorsTestCase assertEquals( "TEST", obj.getStringProperty() ); } { - try - { - TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( new Float( 17.3f ) ) ).get(); - fail( "Expected NoSuchMethodException" ); - } - catch ( NoSuchMethodException e ) - { - // expected - } - } - { TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Boolean.TRUE ) ).get(); assertNotNull( obj ); @@ -110,28 +146,47 @@ public class ConstructorsTestCase } @Test + public void invokeExactConstructorWithInvalidArgument() + throws Exception + { + thrown.expect( NoSuchMethodException.class ); + thrown.expectMessage( "No such accessible constructor on class:" ); + thrown.expectMessage( TestBean.class.getName() ); + on( TestBean.class ).invokeExactConstructor( argument( new Float( 17.3f ) ) ).get(); + } + + @Test( expected = NullPointerException.class ) + public void invokeExactConstructorWithNull() + throws Exception + { + on( TestBean.class ).invokeExactConstructor( (Argument<?>) null ); + } + + @Test public void invokeExactConstructorWithArgArray() throws Exception { - { - try - { - TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( new Float( 17.3f ) ), - argument( "TEST" ) ).get(); - fail( "Expected NoSuchMethodException" ); - } - catch ( NoSuchMethodException e ) - { - // expected - } - } - { - TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Boolean.TRUE ), - argument( "TEST" ) ).get(); - assertNotNull( obj ); - assertEquals( true, obj.isBooleanSecond() ); - assertEquals( "TEST", obj.getStringProperty() ); - } + TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Boolean.TRUE ), + argument( "TEST" ) ).get(); + assertNotNull( obj ); + assertEquals( true, obj.isBooleanSecond() ); + assertEquals( "TEST", obj.getStringProperty() ); + } + + @Test + public void invokeExactConstructorWithInvalidArgArray() throws Exception + { + thrown.expect( NoSuchMethodException.class ); + thrown.expectMessage( "No such accessible constructor on class:" ); + thrown.expectMessage( TestBean.class.getName() ); + on( TestBean.class ).invokeExactConstructor( argument( new Float( 17.3f ) ),argument( "TEST" ) ).get(); + } + + @Test( expected = NullPointerException.class ) + public void invokeExactConstructorWithNullArray() + throws Exception + { + on( TestBean.class ).invokeExactConstructor( null, null, null ); } @Test @@ -160,18 +215,16 @@ public class ConstructorsTestCase assertEquals( 17.3f, obj.getFloatProperty(), 0.0f ); assertEquals( "TEST", obj.getStringProperty() ); } - { - try - { - TestBean obj = on( TestBean.class ).invokeExactConstructor( argument( Float.class, new Float( 17.3f ) ), - argument( String.class, "TEST" ) ).get(); - fail( "Expected NoSuchMethodException" ); - } - catch ( NoSuchMethodException e ) - { - // expected - } - } + } + + @Test + public void invokeExactConstructorWithInvalidTypeArray() throws Exception + { + thrown.expect( NoSuchMethodException.class ); + thrown.expectMessage( "No such accessible constructor on class:" ); + thrown.expectMessage( TestBean.class.getName() ); + on( TestBean.class ).invokeExactConstructor( argument( Float.class, new Float( 17.3f ) ), + argument( String.class, "TEST" ) ).get(); } }