AbstractTilesInitializerServlet extends HttpServlet { @Override public void init() { initializer = createTilesInitializer(); ServletContext adaptedContext = new ServletContextAdapter( getServletConfig()); ServletApplicationContext preliminaryContext = new ServletApplicationContext( adaptedContext); initializer.initialize(preliminaryContext); }  @Override void destroy(); @Override void init();  }
@SuppressWarnings("unchecked") @Test public void testInit() throws ServletException { AbstractTilesInitializerServlet servlet = createMockBuilder(AbstractTilesInitializerServlet.class).createMock(); TilesInitializer initializer = createMock(TilesInitializer.class); ServletConfig config = createMock(ServletConfig.class); ServletContext servletContext = createMock(ServletContext.class); Enumeration<String> names = createMock(Enumeration.class); expect(servlet.createTilesInitializer()).andReturn(initializer); expect(config.getServletContext()).andReturn(servletContext); expect(servletContext.getInitParameterNames()).andReturn(names); expect(config.getInitParameterNames()).andReturn(names); expect(names.hasMoreElements()).andReturn(false).times(2); initializer.initialize(isA(ServletApplicationContext.class)); initializer.destroy(); replay(servlet, initializer, config, servletContext, names); servlet.init(config); servlet.destroy(); verify(servlet, initializer, config, servletContext, names); }