WebAppLoader implements LifeCycle { public Map<String, ServletWrapper> loadOnStartUp() throws Exception { Set<Map.Entry<String, ServletWrapper>> entrySet = router.entrySet(); for (Map.Entry<String, ServletWrapper> wrapperEntry : entrySet) { ServletWrapper wrapper = wrapperEntry.getValue(); Integer loadOnStartup = wrapper.getLoadOnStartup(); if (loadOnStartup != null) { String className = wrapper.getClassName(); Class<? extends Servlet> servletClass = cast(classLoader.loadClass(className)); Servlet servletInstance = servletClass.newInstance(); wrapper.setServlet(servletInstance); wrapper.setServletClass(servletClass); } } return Collections.unmodifiableMap(router); } WebAppLoader(Map<String, ServletWrapper> router, ClassLoader classLoader); @Override void init(); @Override void start(); @Override void destroy(); Map<String, ServletWrapper> loadOnStartUp(); Class<?> loadClass(String name);  }
@Test public void webAppLoaderCanLoadInstanceOfLoadOnStartUp() throws Exception { ClassLoader classLoader = new ServletClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); Map<String, ServletWrapper> router = new HashMap<>(); initRouter(router); WebAppLoader loader = new WebAppLoader(router, classLoader); Map<String, ServletWrapper> actual = loader.loadOnStartUp(); Map<String, ServletWrapper> expect = new HashMap<>(); initExpect(expect); assertEquals(expect, actual); }