SessionHelpers { static void findListenersByIntercepting(ServletContext context, HttpServletRequest request) { if (context.getAttribute(INTROSPECTING_LISTENERS) == null) { logger.info("Started collecting servlet listeners."); context.setAttribute(INTROSPECTING_LISTENERS, new HashSet<Object>()); HttpSession session = request.getSession(); session.setAttribute(DUMMY_ATTRIBUTE, DUMMY_ATTRIBUTE); session.removeAttribute(DUMMY_ATTRIBUTE); session.invalidate(); context.setAttribute(INTROSPECTING_LISTENERS, Boolean.TRUE); logger.info("Finished collecting listeners."); } }  ServletRequest prepareRequest(ServletRequest request, ServletResponse response,
      ServletContext originalServletContext); ServletResponse prepareResponse(ServletRequest request, ServletResponse response); MethodHandle[] initSessionManagement(ServletContext servletContext); MethodHandle[] initSessionManagement(ServletContext servletContext, boolean reset); void commitRequest(ServletRequest request, ServletRequest oldRequest); @SuppressWarnings("unchecked") void interceptHttpListener(EventListener caller, HttpSessionEvent event); void onAddListener(ServletContext servletContext, Object listener);  }
@Test public void testFindListenersByIntercepting() { HttpServletRequest request = mock(HttpServletRequest.class); HttpSession session = mock(HttpSession.class); when(request.getSession()).thenReturn(session); SessionHelpers.findListenersByIntercepting(servletContext, request); ArgumentCaptor<String> attribute = ArgumentCaptor.forClass(String.class); verify(session).setAttribute(attribute.capture(), any(String.class)); verify(session).removeAttribute(attribute.getValue()); verify(session).invalidate(); verify(servletContext).setAttribute(SessionHelpers.INTROSPECTING_LISTENERS, Boolean.TRUE); }