Author: jcarman
Date: Mon Sep  5 15:58:17 2005
New Revision: 278880

URL: http://svn.apache.org/viewcvs?rev=278880&view=rev
Log:
Improving test coverage.

Added:
    
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/
    
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestNullInvocationHandler.java
   (with props)
    
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestReturnTypeFilter.java
   (with props)
Modified:
    
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java
    
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/NullInvocationHandler.java
    
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/AbstractMethodInterceptor.java
    
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java
    
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java

Modified: 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java?rev=278880&r1=278879&r2=278880&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java
 (original)
+++ 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/util/AbstractSubclassingProxyFactory.java
 Mon Sep  5 15:58:17 2005
@@ -87,6 +87,7 @@
 
     /**
      * Returns true if a suitable superclass can be found, given the desired 
<code>proxyClasses</code>.
+     *
      * @param proxyClasses the proxy classes
      * @return true if a suitable superclass can be found, given the desired 
<code>proxyClasses</code>
      */

Modified: 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/NullInvocationHandler.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/NullInvocationHandler.java?rev=278880&r1=278879&r2=278880&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/NullInvocationHandler.java
 (original)
+++ 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/NullInvocationHandler.java
 Mon Sep  5 15:58:17 2005
@@ -18,6 +18,8 @@
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * An [EMAIL PROTECTED] InvocationHandler} implementation which merely returns 
null for all method invocations.  This class is
@@ -28,6 +30,17 @@
  */
 public class NullInvocationHandler implements InvocationHandler
 {
+    private static Map<Class,Object> primitiveValueMap = new 
HashMap<Class,Object>();
+    static
+    {
+        primitiveValueMap.put( Integer.TYPE, new Integer( 0 ) );
+        primitiveValueMap.put( Long.TYPE, new Long( 0 ) );
+        primitiveValueMap.put( Short.TYPE, new Short( ( short )0 ) );
+        primitiveValueMap.put( Byte.TYPE, new Byte( ( byte )0 ) );
+        primitiveValueMap.put( Float.TYPE, new Float( 0.0f ) );
+        primitiveValueMap.put( Double.TYPE, new Double( 0.0 ) );
+        primitiveValueMap.put( Character.TYPE, new Character( ( char )0 ) );
+    }
 
//----------------------------------------------------------------------------------------------------------------------
 // InvocationHandler Implementation
 
//----------------------------------------------------------------------------------------------------------------------
@@ -37,35 +50,7 @@
         final Class<?> returnType = method.getReturnType();
         if( returnType.isPrimitive() )
         {
-            if( Integer.TYPE.equals( returnType ) )
-            {
-                return 0;
-            }
-            else if( Long.TYPE.equals( returnType ) )
-            {
-                return 0L;
-            }
-            else if( Double.TYPE.equals( returnType ) )
-            {
-                return 0.0;
-            }
-            else if( Float.TYPE.equals( returnType ) )
-            {
-                return 0.0f;
-            }
-            else if( Short.TYPE.equals( returnType ) )
-            {
-                return ( short )0;
-            }
-            else if( Character.TYPE.equals( returnType ) )
-            {
-                return ( char )0;
-            }
-            else if( Byte.TYPE.equals( returnType ) )
-            {
-                return ( byte )0;
-            }
-            return 0;
+            return primitiveValueMap.get( returnType );
         }
         else
         {

Modified: 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/AbstractMethodInterceptor.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/AbstractMethodInterceptor.java?rev=278880&r1=278879&r2=278880&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/AbstractMethodInterceptor.java
 (original)
+++ 
jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/AbstractMethodInterceptor.java
 Mon Sep  5 15:58:17 2005
@@ -26,7 +26,12 @@
  */
 public abstract class AbstractMethodInterceptor implements MethodInterceptor
 {
-    protected Log log = LogFactory.getLog( getClass() );
+    protected Log log;
+
+    protected AbstractMethodInterceptor()
+    {
+        setLog( LogFactory.getLog( getClass() ) );
+    }
 
     public Log getLog()
     {

Modified: 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java?rev=278880&r1=278879&r2=278880&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java
 (original)
+++ 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java
 Mon Sep  5 15:58:17 2005
@@ -15,9 +15,7 @@
  * limitations under the License.
  */
 package org.apache.commons.proxy;
-import junit.framework.*;
-import org.apache.commons.proxy.ProxyUtils;
-import org.apache.commons.proxy.factory.cglib.CglibProxyFactory;
+import junit.framework.TestCase;
 import org.apache.commons.proxy.factory.javassist.JavassistProxyFactory;
 import org.apache.commons.proxy.util.Echo;
 
@@ -26,6 +24,14 @@
     public void testCreateNullObject() throws Exception
     {
         final Echo nullEcho = ( Echo )ProxyUtils.createNullObject( new 
JavassistProxyFactory(), Echo.class );
+        assertNull( nullEcho.echoBack( "hello" ) );
+        assertNull( nullEcho.echoBack( "hello", "world" ) );
+        assertEquals( ( int ) 0, nullEcho.echoBack( 12345 ) );
+    }
+
+    public void testCreateNullObjectWithClassLoader() throws Exception
+    {
+        final Echo nullEcho = ( Echo )ProxyUtils.createNullObject( new 
JavassistProxyFactory(), Echo.class.getClassLoader(), Echo.class );
         assertNull( nullEcho.echoBack( "hello" ) );
         assertNull( nullEcho.echoBack( "hello", "world" ) );
         assertEquals( ( int ) 0, nullEcho.echoBack( 12345 ) );

Modified: 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java?rev=278880&r1=278879&r2=278880&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
 (original)
+++ 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
 Mon Sep  5 15:58:17 2005
@@ -17,6 +17,7 @@
 package org.apache.commons.proxy.factory;
 
 import org.apache.commons.proxy.ProxyFactory;
+import org.apache.commons.proxy.exception.ProxyFactoryException;
 import org.apache.commons.proxy.handler.NullInvocationHandler;
 import org.apache.commons.proxy.provider.ConstantProvider;
 import org.apache.commons.proxy.util.Echo;
@@ -41,29 +42,71 @@
         assertFalse( factory.canProxy( NoDefaultConstructorEcho.class ) );
         assertTrue( factory.canProxy( ProtectedConstructorEcho.class ) );
         assertFalse( factory.canProxy( InvisibleEcho.class ) );
+        assertFalse( factory.canProxy( Echo.class, EchoImpl.class, 
String.class ) );
     }
 
     public void testDelegatorWithSuperclass()
     {
-        final Echo echo = ( Echo )factory.createDelegatorProxy( new 
ConstantProvider( new EchoImpl() ), Echo.class, EchoImpl.class );
+        final Echo echo = ( Echo ) factory
+                .createDelegatorProxy( new ConstantProvider( new EchoImpl() ), 
Echo.class, EchoImpl.class );
         assertTrue( echo instanceof EchoImpl );
     }
 
     public void testInterceptorWithSuperclass()
     {
-        final Echo echo = ( Echo )factory.createInterceptorProxy( new 
EchoImpl(), new NoOpMethodInterceptor(), Echo.class, EchoImpl.class );
+        final Echo echo = ( Echo ) factory
+                .createInterceptorProxy( new EchoImpl(), new 
NoOpMethodInterceptor(), Echo.class, EchoImpl.class );
         assertTrue( echo instanceof EchoImpl );
     }
 
     public void testInvocationHandlerWithSuperclass()
     {
-        final Echo echo = ( Echo )factory.createInvocationHandlerProxy( new 
NullInvocationHandler(), Echo.class, EchoImpl.class );
+        final Echo echo = ( Echo ) factory
+                .createInvocationHandlerProxy( new NullInvocationHandler(), 
Echo.class, EchoImpl.class );
         assertTrue( echo instanceof EchoImpl );
     }
 
-    public static final class FinalEcho extends EchoImpl
+    public void testDelegatorWithMultipleSuperclasses()
+    {
+        try
+        {
+            factory.createDelegatorProxy( new ConstantProvider( new EchoImpl() 
),
+                                          EchoImpl.class, String.class );
+            fail();
+        }
+        catch( ProxyFactoryException e )
+        {
+        }
+    }
+
+    public void testInterceptorWithMultipleSuperclasses()
+    {
+        try
+        {
+            factory.createInterceptorProxy( new EchoImpl(), new 
NoOpMethodInterceptor(),
+                                            EchoImpl.class, String.class );
+            fail();
+        }
+        catch( ProxyFactoryException e )
+        {
+        }
+    }
+
+    public void testInvocationHandlerWithMultipleSuperclasses()
     {
+        try
+        {
+            factory.createInvocationHandlerProxy( new NullInvocationHandler(),
+                                                  EchoImpl.class, String.class 
);
+            fail();
+        }
+        catch( ProxyFactoryException e )
+        {
+        }
+    }
 
+    public static final class FinalEcho extends EchoImpl
+    {
     }
 
     public static class NoDefaultConstructorEcho extends EchoImpl
@@ -77,12 +120,10 @@
     {
         protected ProtectedConstructorEcho()
         {
-
         }
     }
 
     private static class InvisibleEcho extends EchoImpl
     {
-
     }
 }

Added: 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestNullInvocationHandler.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestNullInvocationHandler.java?rev=278880&view=auto
==============================================================================
--- 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestNullInvocationHandler.java
 (added)
+++ 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestNullInvocationHandler.java
 Mon Sep  5 15:58:17 2005
@@ -0,0 +1,48 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.commons.proxy.handler;
+import junit.framework.TestCase;
+import org.apache.commons.proxy.ProxyUtils;
+import org.apache.commons.proxy.factory.cglib.CglibProxyFactory;
+
+public class TestNullInvocationHandler extends TestCase
+{
+    public void testReturnValues()
+    {
+        final Tester tester = ( Tester )ProxyUtils.createNullObject( new 
CglibProxyFactory(), Tester.class );
+        assertEquals( 0, tester.intMethod() );
+        assertEquals( 0L, tester.longMethod() );
+        assertEquals( ( short )0, tester.shortMethod() );
+        assertEquals( ( byte )0, tester.byteMethod() );
+        assertEquals( ( char )0, tester.charMethod() );
+        assertEquals( 0.0f, tester.floatMethod() );
+        assertEquals( 0.0, tester.doubleMethod() );
+        assertNull( tester.stringMethod() );
+    }
+
+    public static interface Tester
+    {
+        public int intMethod();
+        public long longMethod();
+        public short shortMethod();
+        public byte byteMethod();
+        public char charMethod();
+        public double doubleMethod();
+        public float floatMethod();
+        public String stringMethod();
+    }
+}
\ No newline at end of file

Propchange: 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestNullInvocationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestNullInvocationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestReturnTypeFilter.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestReturnTypeFilter.java?rev=278880&view=auto
==============================================================================
--- 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestReturnTypeFilter.java
 (added)
+++ 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestReturnTypeFilter.java
 Mon Sep  5 15:58:17 2005
@@ -0,0 +1,32 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.commons.proxy.interceptor.filter;
+import junit.framework.*;
+import org.apache.commons.proxy.interceptor.filter.ReturnTypeFilter;
+
+public class TestReturnTypeFilter extends TestCase
+{
+    public void testAcceptsMethod() throws Exception
+    {
+        final ReturnTypeFilter filter = new ReturnTypeFilter( String.class, 
Integer.TYPE );
+        assertTrue( filter.accepts( Object.class.getMethod( "toString" ) ) );
+        assertTrue( filter.accepts( Object.class.getMethod( "hashCode" ) ) );
+        assertFalse( filter.accepts( Object.class.getMethod( "equals", 
Object.class ) ) );
+    }
+
+
+}
\ No newline at end of file

Propchange: 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestReturnTypeFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestReturnTypeFilter.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to