X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fgeneral%2FLookupProxyFactoryTest.java;h=dd8930c0df88250e0e6d95ef73415e69ec05765c;hb=26805fc0810098c4bd8009a35c8719478e74153e;hp=c7650906ffa2488103a72c606fcd8a6d93aca105;hpb=b16920567f3a7aebadded03b8bd250e6d0876004;p=utils diff --git a/support/general/src/test/java/org/wamblee/general/LookupProxyFactoryTest.java b/support/general/src/test/java/org/wamblee/general/LookupProxyFactoryTest.java index c7650906..dd8930c0 100644 --- a/support/general/src/test/java/org/wamblee/general/LookupProxyFactoryTest.java +++ b/support/general/src/test/java/org/wamblee/general/LookupProxyFactoryTest.java @@ -18,6 +18,8 @@ package org.wamblee.general; import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import java.io.Serializable; + import javax.naming.InitialContext; import org.junit.After; @@ -43,9 +45,9 @@ public class LookupProxyFactoryTest { public void setUp() throws Exception { intf = mock(MyInterface.class); lookup = mock(Lookup.class); - + LookupProxyFactory factory = new LookupProxyFactory( - MyInterface.class, lookup); + MyInterface.class, lookup); proxy = factory.getProxy(); } @@ -65,7 +67,8 @@ public class LookupProxyFactoryTest { @Test(expected = LookupException.class) public void testNotFoundAtJndi() throws Exception { - when(lookup.lookup()).thenThrow(new RuntimeException("Object not found")); + when(lookup.lookup()).thenThrow( + new RuntimeException("Object not found")); proxy.execute(); } @@ -94,4 +97,36 @@ public class LookupProxyFactoryTest { } } + private static final class MyLookup implements Lookup { + + @Override + public Object lookup() throws Exception { + return new MyInterface() { + + @Override + public int execute() { + return 10; + } + }; + } + } + + @Test + public void testProxyMustBerializable() throws Exception { + lookup = new MyLookup(); + LookupProxyFactory factory = new LookupProxyFactory( + MyInterface.class, lookup); + proxy = factory.getProxy(); + + assertEquals(10, proxy.execute()); + + assertTrue(proxy instanceof Serializable); + + proxy = ObjectSerializationUtils.deserialize(ObjectSerializationUtils + .serialize(proxy), MyInterface.class); + + // and it should still work + assertEquals(10, proxy.execute()); + } + }