OzarkServletContextListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { ServletContext servletContext = sce.getServletContext(); Set<Class<?>> controllerClasses = (Set<Class<?>>) servletContext.getAttribute(CONTROLLER_CLASSES); if (controllerClasses == null || controllerClasses.isEmpty()) { return; } for (Class<?> controllerClass : controllerClasses) { failIfNoCdiBean(controllerClass); warnIfAnnotatedWithNamed(controllerClass); } } OzarkServletContextListener();  OzarkServletContextListener(BeanManager beanManager); @Override void contextInitialized(ServletContextEvent sce);  }
@Test(expected = IllegalArgumentException.class) public void failIfControllerIsNoCdiBean() { BeanManager beanManager = createMock(BeanManager.class); ServletContextEvent event = createMock(ServletContextEvent.class); ServletContext context = createMock(ServletContext.class); OzarkServletContextListener listener = new OzarkServletContextListener(beanManager); Set<Class<?>> controllers = new HashSet<>(singletonList(TestController.class)); expect(event.getServletContext()).andStubReturn(context); expect(context.getAttribute(OzarkContainerInitializer.CONTROLLER_CLASSES)).andStubReturn(controllers); expect(beanManager.getBeans(TestController.class)).andStubReturn(new HashSet<>()); EasyMock.replay(event, context, beanManager); listener.contextInitialized(event); }