InstrumentedFilterContextListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { sce.getServletContext().setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE, getMetricRegistry()); }  @Override void contextInitialized(ServletContextEvent sce); @Override void contextDestroyed(ServletContextEvent sce);  }
@Test public void injectsTheMetricRegistryIntoTheServletContext() { final ServletContext context = mock(ServletContext.class); final ServletContextEvent event = mock(ServletContextEvent.class); when(event.getServletContext()).thenReturn(context); listener.contextInitialized(event); verify(context).setAttribute("com.codahale.metrics.servlet.InstrumentedFilter.registry", registry); }