SessionHelpers { static SessionTracking getTracking(ServletContext servletContext, SessionConfiguration sessionConfiguration) { String[] sessionTracking = sessionConfiguration.getSessionTracking(); try { SessionTracking first = null; if (sessionTracking == null || sessionTracking.length == 0) { first = SessionPropagation.DEFAULT.get(); first.configure(sessionConfiguration); } else { SessionTracking prevInstance = null; for (String t : sessionTracking) { SessionTracking instance = trackingFromEnum(t); if (instance == null) { instance = (SessionTracking)newInstance(servletContext, t); } if (first == null) { first = instance; } if (prevInstance != null) { prevInstance.nextSessionTracking(instance); } prevInstance = instance; instance.configure(sessionConfiguration); } } return first; } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException("Unable to load or instantiate SessionTracking class " + sessionTracking, e); } }  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 testGetTracking() { when(servletContext.getClassLoader()).thenReturn(this.getClass().getClassLoader()); SessionConfiguration sessionConfiguration = new SessionConfiguration(); SessionTracking tracking = SessionHelpers.getTracking(servletContext, sessionConfiguration); assertTrue("Expecting instance of CookieSessionTracking", tracking instanceof CookieSessionTracking); sessionConfiguration.setSessionTracking("URL"); tracking = SessionHelpers.getTracking(servletContext, sessionConfiguration); assertTrue("Expecting instance of UrlSessionTracking", tracking instanceof UrlSessionTracking); sessionConfiguration.setSessionTracking(CookieSessionTracking.class.getName()); tracking = SessionHelpers.getTracking(servletContext, sessionConfiguration); assertTrue("Expecting instance of CookieSessionTracking", tracking instanceof CookieSessionTracking); assertTrue(tracking instanceof CookieSessionTracking); verify(servletContext).getClassLoader(); }
@Test public void testTimestamp() { when(servletContext.getClassLoader()).thenReturn(this.getClass().getClassLoader()); SessionConfiguration sessionConfiguration = new SessionConfiguration(); sessionConfiguration.setSessionTracking("URL"); sessionConfiguration.setTimestampSufix(true); SessionTracking tracking = SessionHelpers.getTracking(servletContext, sessionConfiguration); assertTrue(tracking.newId().indexOf("!") > 0); sessionConfiguration.setTimestampSufix(false); tracking = SessionHelpers.getTracking(servletContext, sessionConfiguration); assertTrue(tracking.newId().indexOf("!") < 0); }