From: Erik Brakkee Date: Fri, 30 Jul 2010 18:44:27 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~140 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=a79d50a65191abb5d38ec6729758ea6e7ffa6952;p=utils --- diff --git a/test/enterprise/src/test/java/org/wamblee/test/jndi/JndiProxyFactoryTest.java b/test/enterprise/src/test/java/org/wamblee/test/jndi/LookupProxyFactoryTest.java 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 099135ea..755769d5 100644 --- a/test/enterprise/src/test/java/org/wamblee/test/jndi/JndiProxyFactoryTest.java +++ b/test/enterprise/src/test/java/org/wamblee/test/jndi/LookupProxyFactoryTest.java @@ -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 factory = new JndiProxyFactory( - MyInterface.class, JNDI); + lookup = mock(Lookup.class); + + LookupProxyFactory factory = new LookupProxyFactory( + 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()); } }