SwaggerContainerLifecycleListener implements ContainerLifecycleListener { @Override public void onStartup(final Container container) { String name = context.getServletContextName(); ServletRegistration registration = context.getServletRegistration(name); String scannerId = registration.getInitParameter("swagger.context.id"); String basePath = context.getContextPath(); BeanConfig beanConfig = new BeanConfig(); beanConfig.setResourcePackage(classPath); beanConfig.setScannerId(scannerId); beanConfig.setBasePath(basePath); beanConfig.setUsePathBasedConfig(true); beanConfig.setScan(true); } SwaggerContainerLifecycleListener(final String classPath); ServletContext getContext(); void setContext(final ServletContext context); @Override void onStartup(final Container container); @Override void onReload(final Container container); @Override void onShutdown(final Container container);  }
@Test public void onStartup() { Container container = mock(Container.class); listener.onStartup(container); Mockito.verifyNoMoreInteractions(container); SwaggerScannerLocator locator = SwaggerScannerLocator.getInstance(); Scanner scanner = locator.getScanner("ScannerId"); assertNotNull(scanner); }