### Question:
CDIBeanNameResolver implements ELBeanNameResolver { public boolean init(ServletContext servletContext, ClassLoader classLoader) { try { Class<?> beanManagerClass = classLoader.loadClass(BEAN_MANAGER_CLASS); getBeansMethod = beanManagerClass.getMethod(GET_BEANS_METHOD, Type.class, Annotation[].class); Class<?> beanClass = classLoader.loadClass(BEAN_CLASS); getNameMethod = beanClass.getMethod(GET_NAME_METHOD); } catch (ClassNotFoundException e) { if (log.isDebugEnabled()) { log.debug("BeanManager or Bean class not found. CDI resolver has been disabled."); } return false; } catch (NoSuchMethodException e) { log.warn("Cannot find BeanManager.getBeans() or Bean.getName() method", e); return false; } catch (SecurityException e) { log.warn("Unable to init resolver due to security restrictions", e); return false; } beanManager = getBeanManagerFromServletContext(servletContext, BEAN_MANAGER_CLASS); if (beanManager == null) { beanManager = getBeanManagerFromServletContext(servletContext, SERVLET_CONTEXT_ATTR_WELD_1_1); } if (beanManager == null) { beanManager = getBeanManagerFromJNDI(BEAN_MANAGER_JNDI); } if (beanManager == null) { beanManager = getBeanManagerFromJNDI(BEAN_MANAGER_JNDI_TOMCAT); } if (beanManager == null) { if (log.isDebugEnabled()) { log.debug("BeanManager cannot be found! CDI resolver gets disabled!"); } return false; } if (log.isDebugEnabled()) { log.debug("CDI environment detected. Enabling bean name resolving via BeanManager."); } return true; }  boolean init(ServletContext servletContext, ClassLoader classLoader); String getBeanName(Class<?> clazz); final static String BEAN_MANAGER_JNDI; final static String BEAN_MANAGER_JNDI_TOMCAT; final static String SERVLET_CONTEXT_ATTR_WELD_1_1; final static String BEAN_MANAGER_CLASS; final static String GET_BEANS_METHOD; final static String GET_NAME_METHOD; }### Answer:
@Test public void testNoCDIEnvironment() throws Exception { ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class); ClassLoader classLoader = EasyMock.createNiceMock(ClassLoader.class); EasyMock.expect(classLoader.loadClass((String) EasyMock.anyObject())).andThrow(new ClassNotFoundException()) .once(); EasyMock.replay(classLoader); CDIBeanNameResolver resolver = new CDIBeanNameResolver(); boolean initCompleted = resolver.init(servletContext, classLoader); assertFalse(initCompleted); }