Author: britter
Date: Sat Feb 16 12:43:14 2013
New Revision: 1446886

URL: http://svn.apache.org/r1446886
Log:
Add test case for BeanAccessor.cast()

Added:
    
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/CastTestCase.java
   (with props)

Added: 
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/CastTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/CastTestCase.java?rev=1446886&view=auto
==============================================================================
--- 
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/CastTestCase.java
 (added)
+++ 
commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/CastTestCase.java
 Sat Feb 16 12:43:14 2013
@@ -0,0 +1,75 @@
+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.BeanUtils.on;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class CastTestCase
+{
+
+    private SuperClass superObj;
+
+    private SubClass subObj;
+
+    @Before
+    public void setUp()
+    {
+        superObj = new SuperClass();
+        subObj = new SubClass();
+    }
+
+    @Test
+    public void castSameClass()
+    {
+        SuperClass casted = on( superObj ).cast();
+        assertNotNull( casted );
+        assertSame( superObj, casted );
+    }
+
+    @Test
+    public void castCompatible()
+    {
+        SuperClass casted = on( subObj ).cast();
+        assertNotNull( casted );
+        assertSame( subObj, casted );
+    }
+
+    @Test( expected = ClassCastException.class )
+    public void castIncompatible()
+    {
+        @SuppressWarnings( "unused" ) // need to assign to casted to force 
exception
+        SubClass casted = on( superObj ).cast();
+    }
+
+    private static class SuperClass
+    {
+
+    }
+
+    private static class SubClass
+        extends SuperClass
+    {
+
+    }
+
+}

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


Reply via email to