commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1234115 - in /commons/sandbox/beanutils2/trunk/src: changes/changes.xml test/java/org/apache/commons/beanutils2/ArgumentTest.java
Date Fri, 20 Jan 2012 20:32:59 GMT
Author: simonetripodi
Date: Fri Jan 20 20:32:58 2012
New Revision: 1234115

URL: http://svn.apache.org/viewvc?rev=1234115&view=rev
Log:
[SANDBOX-362] Create basic unit tests for all classes - test class submitted by Benedikt Ritter

Added:
    commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ArgumentTest.java
  (with props)
Modified:
    commons/sandbox/beanutils2/trunk/src/changes/changes.xml

Modified: commons/sandbox/beanutils2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/changes/changes.xml?rev=1234115&r1=1234114&r2=1234115&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/beanutils2/trunk/src/changes/changes.xml Fri Jan 20 20:32:58 2012
@@ -23,7 +23,9 @@
   </properties>
   <body>
   <release version="0.1" date="201?-??-??" description="First release.">
-    
+    <action dev="simonetripodi" type="update" issue="SANDBOX-352" due-to="Benedikt Ritter">
+      Create basic unit tests for all classes.
+    </action>
   </release>
   </body>
 </document>

Added: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ArgumentTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ArgumentTest.java?rev=1234115&view=auto
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ArgumentTest.java
(added)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ArgumentTest.java
Fri Jan 20 20:32:58 2012
@@ -0,0 +1,189 @@
+package org.apache.commons.beanutils2;
+
+/*
+ * 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.
+ */
+
+import static org.apache.commons.beanutils2.Argument.argument;
+import static org.apache.commons.beanutils2.Argument.nullArgument;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+public class ArgumentTest
+{
+
+    @Test
+    public void testArgumentA()
+    {
+        Argument<Byte> byteArg = argument( new Byte( (byte) 7 ) );
+        assertEquals( (byte) 7, byteArg.getValue().byteValue() );
+        assertEquals( Byte.class, byteArg.getType() );
+
+        Argument<Short> shortArg = argument( new Short( (short) 16 ) );
+        assertEquals( (short) 16, shortArg.getValue().shortValue() );
+        assertEquals( Short.class, shortArg.getType() );
+
+        Argument<Integer> intArg = argument( 2 );
+        assertEquals( 2, intArg.getValue().intValue() );
+        assertEquals( Integer.class, intArg.getType() );
+
+        Argument<Long> longArg = argument( 76l );
+        assertEquals( 76l, longArg.getValue().longValue() );
+        assertEquals( Long.class, longArg.getType() );
+
+        Argument<Float> floatArg = argument( 23.7f );
+        assertEquals( 23.7f, floatArg.getValue().floatValue(), 0.0d );
+        assertEquals( Float.class, floatArg.getType() );
+
+        Argument<Double> doubleArg = argument( 289.6d );
+        assertEquals( 289.6d, doubleArg.getValue().doubleValue(), 0.0d );
+        assertEquals( Double.class, doubleArg.getType() );
+
+        Argument<Character> charArg = argument( 'X' );
+        assertEquals( 'X', charArg.getValue().charValue() );
+        assertEquals( Character.class, charArg.getType() );
+
+        Argument<String> stringArg = argument( "Hello World!" );
+        assertEquals( "Hello World!", stringArg.getValue() );
+        assertEquals( String.class, stringArg.getType() );
+
+        Object valueObj = new Object();
+        Argument<Object> objArg = argument( valueObj );
+        assertEquals( valueObj, objArg.getValue() );
+        assertEquals( Object.class, objArg.getType() );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testArgumentNull()
+    {
+        argument( null );
+    }
+
+    @Test
+    public void testNullArgument()
+    {
+        Argument<Byte> byteArg = nullArgument( Byte.class );
+        assertNull( byteArg.getValue() );
+        assertEquals( Byte.class, byteArg.getType() );
+
+        Argument<Short> shortArg = nullArgument( Short.class );
+        assertNull( shortArg.getValue() );
+        assertEquals( Short.class, shortArg.getType() );
+
+        Argument<Integer> intArg = nullArgument( Integer.class );
+        assertNull( intArg.getValue() );
+        assertEquals( Integer.class, intArg.getType() );
+
+        Argument<Long> longArg = nullArgument( Long.class );
+        assertNull( longArg.getValue() );
+        assertEquals( Long.class, longArg.getType() );
+
+        Argument<Float> floatArg = nullArgument( Float.class );
+        assertNull( floatArg.getValue() );
+        assertEquals( Float.class, floatArg.getType() );
+
+        Argument<Double> doubleArg = nullArgument( Double.class );
+        assertNull( doubleArg.getValue() );
+        assertEquals( Double.class, doubleArg.getType() );
+
+        Argument<Character> charArg = nullArgument( Character.class );
+        assertNull( charArg.getValue() );
+        assertEquals( Character.class, charArg.getType() );
+
+        Argument<String> stringArg = nullArgument( String.class );
+        assertNull( stringArg.getValue() );
+        assertEquals( String.class, stringArg.getType() );
+
+        Argument<Object> objArg = nullArgument( Object.class );
+        assertNull( objArg.getValue() );
+        assertEquals( Object.class, objArg.getType() );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testNullArgumentNull()
+    {
+        nullArgument( null );
+    }
+
+    @Test
+    public void testArgumentClassOfTV()
+    {
+        Argument<Object> byteArg = argument( Object.class, new Byte( (byte) 7 ) );
+        assertEquals( (byte) 7, ( (Byte) byteArg.getValue() ).byteValue() );
+        assertEquals( Object.class, byteArg.getType() );
+
+        Argument<Object> shortArg = argument( Object.class, new Short( (short) 16 )
);
+        assertEquals( (short) 16, ( (Short) shortArg.getValue() ).shortValue() );
+        assertEquals( Object.class, shortArg.getType() );
+
+        Argument<Object> intArg = argument( Object.class, 2 );
+        assertEquals( 2, ( (Integer) intArg.getValue() ).intValue() );
+        assertEquals( Object.class, intArg.getType() );
+
+        Argument<Object> longArg = argument( Object.class, 76l );
+        assertEquals( 76l, ( (Long) longArg.getValue() ).longValue() );
+        assertEquals( Object.class, longArg.getType() );
+
+        Argument<Object> floatArg = argument( Object.class, 23.7f );
+        assertEquals( 23.7f, ( (Float) floatArg.getValue() ).floatValue(), 0.0d );
+        assertEquals( Object.class, floatArg.getType() );
+
+        Argument<Object> doubleArg = argument( Object.class, 289.6d );
+        assertEquals( 289.6d, ( (Double) doubleArg.getValue() ).doubleValue(), 0.0d );
+        assertEquals( Object.class, doubleArg.getType() );
+
+        Argument<Object> charArg = argument( Object.class, 'X' );
+        assertEquals( 'X', ( (Character) charArg.getValue() ).charValue() );
+        assertEquals( Object.class, charArg.getType() );
+
+        Argument<Object> stringArg = argument( Object.class, "Hello World!" );
+        assertEquals( "Hello World!", stringArg.getValue() );
+        assertEquals( Object.class, stringArg.getType() );
+
+        Object valueObj = new Object();
+        Argument<Object> objArg = argument( Object.class, valueObj );
+        assertEquals( valueObj, objArg.getValue() );
+        assertEquals( Object.class, objArg.getType() );
+    }
+
+    @Test
+    public void testArgumentClassOfTVNull()
+    {
+        try
+        {
+            argument( null, null );
+            fail( "NullPointerException was not thrown!" );
+        }
+        catch ( NullPointerException e )
+        {
+            // do nothing here, we want this exception to be thrown!
+        }
+
+        try
+        {
+            argument( null, 25 );
+            fail( "NullPointerException was not thrown!" );
+        }
+        catch ( NullPointerException e )
+        {
+            // do nothing here, we want this exception to be thrown!
+        }
+    }
+
+}

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ArgumentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ArgumentTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/ArgumentTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message