TomcatResourceFactory { public static Object create(String jndiName, StandardContext standardContext) throws NamingException { if (standardContext == null) { return null; } Context context = standardContext.getNamingContextListener().getEnvContext(); try { if (context != null) { return context.lookup(jndiName); } else { return null; } } catch (NamingException e) { LOGGER.error("Error while looking up " + jndiName, e); throw(e); } }  static Object create(String jndiName, StandardContext standardContext);  }
@Test public void testCreate() throws Exception { NamingContext namingContext = new MyNamingContext(null, null); NamingContextListener namingContextListener = new MyNamingContextListener(namingContext); StandardContext standardContext = new StandardContext(); standardContext.setNamingContextListener(namingContextListener); TomcatResourceFactory.create(name, standardContext); }