DefaultJndiSupport extends JndiLocatorSupport implements
        JndiSupport { @Override public Object lookup(String name) { if (name == null) { log.error("Illegal arguments error : name=" + name); throw new IllegalArgumentException(); } String jndiNameToUse = convertJndiName(name); try { return getJndiTemplate().lookup(jndiNameToUse); } catch (NamingException e) { log.error("Illegal JNDI context name."); throw new JndiException(e); } } DefaultJndiSupport(); void setJndiPrefix(boolean jndiPrefix); boolean isJndiPrefix(); Map<String, String> getJndiEnvironmentMap(); void setJndiEnvironmentMap(Map<String, String> jndiEnvironmentMap); void initialize(); @Override void rebind(String name, Object obj); @Override void unbind(String name); @Override Object lookup(String name);  }
@Test public void testLookup01() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = null; try { support.lookup(name); fail(); } catch (IllegalArgumentException e) { assertThat(logger.getLoggingEvents(), is(asList(error( "Illegal arguments error : name=null")))); } }
@Test public void testLookup02() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = ""; DefaultJndiSupport_JndiTemplateStub01 template = new DefaultJndiSupport_JndiTemplateStub01(); template.setCallLookup(false); template.setJndiNameToUse(null); support.setJndiTemplate(template); support.setResourceRef(false); Object result = support.lookup(name); boolean b = template.isCallLookup(); assertTrue(b); assertEquals("", template.getJndiNameToUse()); assertEquals("return", result); }
@Test public void testLookup03() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = "abc"; DefaultJndiSupport_JndiTemplateStub01 template = new DefaultJndiSupport_JndiTemplateStub01(); template.setCallLookup(false); template.setJndiNameToUse(null); support.setJndiTemplate(template); support.setResourceRef(true); Object result = support.lookup(name); boolean b = template.isCallLookup(); assertTrue(b); assertEquals("java:comp/env/abc", template.getJndiNameToUse()); assertEquals("return", result); }
@Test public void testLookup04() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = "java:comp/env/abc"; DefaultJndiSupport_JndiTemplateStub02 template = new DefaultJndiSupport_JndiTemplateStub02(); template.setCallLookup(false); template.setJndiNameToUse(null); support.setJndiTemplate(template); support.setResourceRef(false); try { support.lookup(name); fail(); } catch (JndiException e) { boolean b = template.isCallLookup(); assertTrue(b); assertEquals("java:comp/env/abc", template.getJndiNameToUse()); assertThat(logger.getLoggingEvents(), is(asList(error( "Illegal JNDI context name.")))); assertEquals(NamingException.class.getName(), e.getCause() .getClass().getName()); } }