commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r631345 - /commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
Date Tue, 26 Feb 2008 19:24:40 GMT
Author: jcarman
Date: Tue Feb 26 11:24:32 2008
New Revision: 631345

URL: http://svn.apache.org/viewvc?rev=631345&view=rev
Log:
PROXY-7: CGLIB Implementation Should Cache Proxy Classes
Added test cases to ensure that proxy classes are reused.

Modified:
    commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java

Modified: commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java?rev=631345&r1=631344&r2=631345&view=diff
==============================================================================
--- commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
(original)
+++ commons/proper/proxy/trunk/src/test/java/org/apache/commons/proxy/factory/AbstractSubclassingProxyFactoryTestCase.java
Tue Feb 26 11:24:32 2008
@@ -31,73 +31,100 @@
  */
 public abstract class AbstractSubclassingProxyFactoryTestCase extends AbstractProxyFactoryTestCase
 {
-    protected AbstractSubclassingProxyFactoryTestCase( ProxyFactory factory )
+    protected AbstractSubclassingProxyFactoryTestCase(ProxyFactory factory)
     {
-        super( factory );
+        super(factory);
     }
 
     public void testWithAbstractSuperclass()
     {
-        final Echo echo = ( Echo )factory.createDelegatorProxy( new ConstantProvider( new
EchoImpl() ),  new Class[] { AbstractEcho.class } );
-        assertEquals( "hello", echo.echoBack( "hello" ) );
-        assertEquals( "helloworld", echo.echoBack( "hello", "world" ) );
+        final Echo echo = (Echo) factory.createDelegatorProxy(new ConstantProvider(new EchoImpl()),
new Class[]{AbstractEcho.class});
+        assertEquals("hello", echo.echoBack("hello"));
+        assertEquals("helloworld", echo.echoBack("hello", "world"));
     }
 
     public void testCanProxy()
     {
-        assertTrue( factory.canProxy(  new Class[] { Echo.class } ) );
-        assertTrue( factory.canProxy(  new Class[] { EchoImpl.class } ) );
-        assertFalse( factory.canProxy(  new Class[] { FinalEcho.class } ) );
-        assertTrue( factory.canProxy(  new Class[] { FinalMethodEcho.class, Echo.class }
) );
-        assertFalse( factory.canProxy(  new Class[] { NoDefaultConstructorEcho.class } )
);
-        assertTrue( factory.canProxy(  new Class[] { ProtectedConstructorEcho.class } ) );
-        assertFalse( factory.canProxy(  new Class[] { InvisibleEcho.class } ) );
-        assertFalse( factory.canProxy(  new Class[] { Echo.class, EchoImpl.class, String.class
} ) );
+        assertTrue(factory.canProxy(new Class[]{Echo.class}));
+        assertTrue(factory.canProxy(new Class[]{EchoImpl.class}));
+        assertFalse(factory.canProxy(new Class[]{FinalEcho.class}));
+        assertTrue(factory.canProxy(new Class[]{FinalMethodEcho.class, Echo.class}));
+        assertFalse(factory.canProxy(new Class[]{NoDefaultConstructorEcho.class}));
+        assertTrue(factory.canProxy(new Class[]{ProtectedConstructorEcho.class}));
+        assertFalse(factory.canProxy(new Class[]{InvisibleEcho.class}));
+        assertFalse(factory.canProxy(new Class[]{Echo.class, EchoImpl.class, String.class}));
     }
 
-    public void testDelegatorWithSuperclass()
+    public void testDelegatorClassReuse()
     {
-        final Echo echo = ( Echo ) factory
-                .createDelegatorProxy( new ConstantProvider( new EchoImpl() ),  new Class[]
{ Echo.class, EchoImpl.class } );
-        assertTrue( echo instanceof EchoImpl );
+        final Echo echo1 = (Echo) factory
+                .createDelegatorProxy(new ConstantProvider(new EchoImpl()), new Class[]{Echo.class,
EchoImpl.class});
+        final Echo echo2 = (Echo) factory
+                .createDelegatorProxy(new ConstantProvider(new EchoImpl()), new Class[]{Echo.class,
EchoImpl.class});
+        assertSame("Delegator proxy classes should be reused.", echo1.getClass(), echo2.getClass());
     }
 
-    public void testInterceptorWithSuperclass()
+    public void testInterceptorClassReuse()
     {
-        final Echo echo = ( Echo ) factory
-                .createInterceptorProxy( new EchoImpl(), new NoOpMethodInterceptor(),  new
Class[] { Echo.class, EchoImpl.class } );
-        assertTrue( echo instanceof EchoImpl );
+        final Echo echo1 = (Echo) factory
+                .createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), new
Class[]{Echo.class, EchoImpl.class});
+        final Echo echo2 = (Echo) factory
+                .createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), new
Class[]{Echo.class, EchoImpl.class});
+        assertSame("Interceptor proxy classes should be reused.", echo1.getClass(), echo2.getClass());
     }
 
-    public void testInvocationHandlerWithSuperclass()
+    public void testInvokerClassReuse()
+    {
+        final Echo echo1 = (Echo) factory
+                .createInvokerProxy(new NullInvoker(), new Class[]{Echo.class, EchoImpl.class});
+        final Echo echo2 = (Echo) factory
+                .createInvokerProxy(new NullInvoker(), new Class[]{Echo.class, EchoImpl.class});
+        assertSame("Invoker proxy classes should be reused.", echo1.getClass(), echo2.getClass());
+    }
+
+    public void testInvokerWithSuperclass()
+    {
+        final Echo echo = (Echo) factory
+                .createInvokerProxy(new NullInvoker(), new Class[]{Echo.class, EchoImpl.class});
+        assertTrue(echo instanceof EchoImpl);
+    }
+
+    public void testDelegatorWithSuperclass()
+    {
+        final Echo echo = (Echo) factory
+                .createDelegatorProxy(new ConstantProvider(new EchoImpl()), new Class[]{Echo.class,
EchoImpl.class});
+        assertTrue(echo instanceof EchoImpl);
+    }
+
+    public void testInterceptorWithSuperclass()
     {
-        final Echo echo = ( Echo ) factory
-                .createInvokerProxy( new NullInvoker(),  new Class[] { Echo.class, EchoImpl.class
} );
-        assertTrue( echo instanceof EchoImpl );
+        final Echo echo = (Echo) factory
+                .createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), new
Class[]{Echo.class, EchoImpl.class});
+        assertTrue(echo instanceof EchoImpl);
     }
 
     public void testProxiesWithClashingFinalMethodInSuperclass()
     {
         final Class[] proxyClasses = new Class[]{Echo.class, FinalMethodEcho.class};
-        Echo proxy = ( Echo )factory.createDelegatorProxy( new ConstantProvider( new EchoImpl()
), proxyClasses );
-        assertEquals( "final", proxy.echoBack("echo") );
+        Echo proxy = (Echo) factory.createDelegatorProxy(new ConstantProvider(new EchoImpl()),
proxyClasses);
+        assertEquals("final", proxy.echoBack("echo"));
 
-        proxy = ( Echo )factory.createInterceptorProxy( new EchoImpl(), new NoOpMethodInterceptor(),
proxyClasses );
-        assertEquals( "final", proxy.echoBack("echo") );
+        proxy = (Echo) factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(),
proxyClasses);
+        assertEquals("final", proxy.echoBack("echo"));
 
-        proxy = ( Echo )factory.createInvokerProxy( new NullInvoker(), proxyClasses );
-        assertEquals( "final", proxy.echoBack("echo") );
+        proxy = (Echo) factory.createInvokerProxy(new NullInvoker(), proxyClasses);
+        assertEquals("final", proxy.echoBack("echo"));
     }
 
     public void testDelegatorWithMultipleSuperclasses()
     {
         try
         {
-            factory.createDelegatorProxy( new ConstantProvider( new EchoImpl() ),
-                                           new Class[] { EchoImpl.class, String.class } );
+            factory.createDelegatorProxy(new ConstantProvider(new EchoImpl()),
+                    new Class[]{EchoImpl.class, String.class});
             fail();
         }
-        catch( ProxyFactoryException e )
+        catch (ProxyFactoryException e)
         {
         }
     }
@@ -106,11 +133,11 @@
     {
         try
         {
-            factory.createInterceptorProxy( new EchoImpl(), new NoOpMethodInterceptor(),
-                                             new Class[] { EchoImpl.class, String.class }
);
+            factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(),
+                    new Class[]{EchoImpl.class, String.class});
             fail();
         }
-        catch( ProxyFactoryException e )
+        catch (ProxyFactoryException e)
         {
         }
     }
@@ -119,11 +146,11 @@
     {
         try
         {
-            factory.createInvokerProxy( new NullInvoker(),
-                                                   new Class[] { EchoImpl.class, String.class
} );
+            factory.createInvokerProxy(new NullInvoker(),
+                    new Class[]{EchoImpl.class, String.class});
             fail();
         }
-        catch( ProxyFactoryException e )
+        catch (ProxyFactoryException e)
         {
         }
     }
@@ -134,7 +161,7 @@
 
     public static class FinalMethodEcho extends EchoImpl
     {
-        public final String echoBack( String message )
+        public final String echoBack(String message)
         {
             return "final";
         }
@@ -142,7 +169,7 @@
 
     public static class NoDefaultConstructorEcho extends EchoImpl
     {
-        public NoDefaultConstructorEcho( String param )
+        public NoDefaultConstructorEcho(String param)
         {
         }
     }



Mime
View raw message