DefaultJndiSupport extends JndiLocatorSupport implements
        JndiSupport { @Override public void rebind(String name, Object obj) { if (name == null || obj == null) { log.error("Illegal arguments error : name=" + name + ", obj=" + obj); throw new IllegalArgumentException(); } String jndiNameToUse = convertJndiName(name); try { getJndiTemplate().rebind(jndiNameToUse, obj); } 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 testRebind01() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = null; Object obj = "abc"; try { support.rebind(name, obj); fail(); } catch (IllegalArgumentException e) { assertThat(logger.getLoggingEvents(), is(asList(error( "Illegal arguments error : name=null, obj=abc")))); } }
@Test public void testRebind02() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = ""; Object obj = "abc"; DefaultJndiSupport_JndiTemplateStub01 template = new DefaultJndiSupport_JndiTemplateStub01(); template.setCallRebind(false); template.setJndiNameToUse(null); template.setObj(null); support.setJndiTemplate(template); support.setResourceRef(false); support.rebind(name, obj); boolean b = template.isCallRebind(); assertTrue(b); assertEquals("", template.getJndiNameToUse()); assertEquals("abc", template.getObj()); }
@Test public void testRebind03() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = "abc"; Object obj = null; try { support.rebind(name, obj); fail(); } catch (IllegalArgumentException e) { assertThat(logger.getLoggingEvents(), is(asList(error( "Illegal arguments error : name=abc, obj=null")))); } }
@Test public void testRebind04() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = "abc"; Object obj = "abc"; DefaultJndiSupport_JndiTemplateStub01 template = new DefaultJndiSupport_JndiTemplateStub01(); template.setCallRebind(false); template.setJndiNameToUse(null); template.setObj(null); support.setJndiTemplate(template); support.setResourceRef(true); support.rebind(name, obj); boolean b = template.isCallRebind(); assertTrue(b); assertEquals("java:comp/env/abc", template.getJndiNameToUse()); assertEquals("abc", template.getObj()); }
@Test public void testRebind05() throws Exception { DefaultJndiSupport support = new DefaultJndiSupport(); String name = "java:comp/env/abc"; Object obj = "abc"; DefaultJndiSupport_JndiTemplateStub02 template = new DefaultJndiSupport_JndiTemplateStub02(); template.setCallRebind(false); template.setJndiNameToUse(null); template.setObj(null); support.setJndiTemplate(template); support.setResourceRef(false); try { support.rebind(name, obj); fail(); } catch (JndiException e) { boolean b = template.isCallRebind(); assertTrue(b); assertEquals("java:comp/env/abc", template.getJndiNameToUse()); assertEquals("abc", template.getObj()); assertEquals(NamingException.class.getName(), e.getCause() .getClass().getName()); assertThat(logger.getLoggingEvents(), is(asList(error( "Illegal JNDI context name.")))); } }