import org.junit.Before;
import org.junit.Test;
import org.wamblee.general.ThreadSpecificProxyFactory;
+import org.wamblee.general.ThreadSpecificProxyFactory.CreationCallback;
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 {