ServletContainerImpl implements ServletContainer { @Override public Filter getFilterForClass(final Class<? extends Filter> filterClass, final FilterConfig filterConfig) throws FilterInitializationException, ServletException { if (filters.containsKey(filterClass)) { return filters.get(filterClass); } Filter filter = instantiateFilter(filterClass); filter.init(filterConfig); filters.put(filterClass, filter); return filter; } ServletContainerImpl(final DateProvider dateProvider,
                                final long servletTimeToLiveInMs,
                                final long monitoringIntervalInMs); @Override Servlet getServletForClass(final Class<? extends HttpServlet> servletClass, final ServletConfig servletConfig); @Override Filter getFilterForClass(final Class<? extends Filter> filterClass, final FilterConfig filterConfig); @Override void shutdown(); Map<Class<? extends HttpServlet>, ServletStats> getServletStats();  }
@Test public void shouldInitializeFilter() throws Exception { SampleFilter filter = (SampleFilter) servletContainer.getFilterForClass(SampleFilter.class, filterConfig); assertThat(filter, is(not(nullValue()))); assertThat(filter.getFilterConfig(), is(equalTo(filterConfig))); assertThat(filter.getFilterConfig().getServletContext(), is(notNullValue())); }
@Test(expected = FilterInitializationException.class) public void shouldThrowExceptionWhenInitializingInvalidFilter() throws Exception { servletContainer.getFilterForClass(InvalidAbstractFilterWithPrivateConstructor.class, filterConfig); }