(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Jul 2010 18:44:27 +0000 (18:44 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Jul 2010 18:44:27 +0000 (18:44 +0000)
test/enterprise/src/test/java/org/wamblee/test/jndi/LookupProxyFactoryTest.java [moved from test/enterprise/src/test/java/org/wamblee/test/jndi/JndiProxyFactoryTest.java with 61% similarity]

similarity index 61%
rename from test/enterprise/src/test/java/org/wamblee/test/jndi/JndiProxyFactoryTest.java
rename to test/enterprise/src/test/java/org/wamblee/test/jndi/LookupProxyFactoryTest.java
index 099135ea237b301f056a30658efa2983aa558621..755769d5deccdf29e71627a942f26f18968f2d98 100644 (file)
@@ -23,11 +23,10 @@ import javax.naming.InitialContext;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.wamblee.test.jndi.JndiProxyFactory;
-import org.wamblee.test.jndi.StubInitialContextFactory;
-import org.wamblee.test.jndi.JndiProxyFactory.JndiWiringException;
+import org.wamblee.test.jndi.LookupProxyFactory.Lookup;
+import org.wamblee.test.jndi.LookupProxyFactory.LookupException;
 
-public class JndiProxyFactoryTest {
+public class LookupProxyFactoryTest {
 
     private static final String NAA_NA_NA_NAA_NA = "naa, na, na, naa, na";
 
@@ -35,61 +34,62 @@ public class JndiProxyFactoryTest {
         int execute();
     }
 
-    private static final String JNDI = "jndi/xyz";
     private MyInterface intf;
-    private InitialContext ctx;
+    private Lookup lookup;
     private MyInterface proxy;
 
     @Before
     public void setUp() throws Exception {
-        StubInitialContextFactory.register();
         intf = mock(MyInterface.class);
-        ctx = new InitialContext();
-        JndiProxyFactory<MyInterface> factory = new JndiProxyFactory<MyInterface>(
-            MyInterface.class, JNDI);
+        lookup = mock(Lookup.class);
+        
+        LookupProxyFactory<MyInterface> factory = new LookupProxyFactory<MyInterface>(
+            MyInterface.class, lookup); 
         proxy = factory.getProxy();
     }
 
     @After
     public void tearDown() throws Exception {
-        StubInitialContextFactory.unregister();
+        // Empty.
     }
 
     @Test
-    public void testFoundAtJndi() throws Exception {
-        ctx.bind(JNDI, intf);
+    public void testFound() throws Exception {
         when(intf.execute()).thenReturn(1);
+        when(lookup.lookup()).thenReturn(intf);
+
         assertEquals(1, proxy.execute());
 
     }
 
-    @Test(expected = JndiWiringException.class)
-    public void testNotFoundAtJndi() {
+    @Test(expected = LookupException.class)
+    public void testNotFoundAtJndi() throws Exception {
+        when(lookup.lookup()).thenThrow(new RuntimeException("Object not found"));
         proxy.execute();
     }
 
-    @Test(expected = JndiWiringException.class)
+    @Test(expected = LookupException.class)
     public void testWrongTypeAtJndi() throws Exception {
-        ctx.bind(JNDI, "a string type");
+        when(lookup.lookup()).thenReturn("my string");
         when(intf.execute()).thenReturn(1);
-        assertEquals(1, proxy.execute());
+        proxy.execute();
     }
 
-    @Test(expected = JndiWiringException.class )
+    @Test(expected = LookupException.class)
     public void testNullAtJndi() throws Exception {
-        ctx.bind(JNDI, null);
+        when(lookup.lookup()).thenReturn(null);
         when(intf.execute()).thenReturn(1);
-        assertEquals(1, proxy.execute());
+        proxy.execute();
     }
 
     @Test
     public void testFoundButInvocationThrowsException() throws Exception {
-        ctx.bind(JNDI, intf);
         when(intf.execute()).thenThrow(new RuntimeException(NAA_NA_NA_NAA_NA));
-        try{ 
-           proxy.execute();
-        } catch (RuntimeException e) { 
-            assertEquals(NAA_NA_NA_NAA_NA, e.getMessage()); 
+        when(lookup.lookup()).thenReturn(intf);
+        try {
+            proxy.execute();
+        } catch (RuntimeException e) {
+            assertEquals(NAA_NA_NA_NAA_NA, e.getMessage());
         }
     }