(no commit message)
[utils] / support / general / src / test / java / org / wamblee / general / ThreadSpecificProxyFactoryTest.java
index 9b52817e5251bb241437cd6b685f428b86cee52a..bbb395090f0a49351595d24a6284c208a9366be1 100644 (file)
@@ -23,6 +23,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.wamblee.general.ThreadSpecificProxyFactory;
+import org.wamblee.general.ThreadSpecificProxyFactory.CreationCallback;
 
 public class ThreadSpecificProxyFactoryTest {
 
@@ -57,6 +58,20 @@ public class ThreadSpecificProxyFactoryTest {
         assertEquals(50, proxy.execute(10));
         verify(svc).execute(10);
     }
+    
+    @Test
+    public void testCreationCallback() throws Exception { 
+        CreationCallback callback = mock(CreationCallback.class);
+        Service initialService = mock(Service.class); 
+        when(callback.create()).thenReturn(initialService);
+        
+        factory = new ThreadSpecificProxyFactory<Service>(Service.class, callback);
+        proxy = factory.getProxy();
+        Service svc = factory.get();
+        
+        assertSame(initialService, svc); 
+        verify(callback).create();
+    }
 
     @Test
     public void testInvokeThroughProxyWithException() throws Exception {