SessionHelpers { static SessionConfiguration initConf(final ServletContext context) { SessionConfiguration sessionConfiguration = (SessionConfiguration)context.getAttribute(SESSION_CONFIGURATION); if (sessionConfiguration == null) { sessionConfiguration = new SessionConfiguration(); context.setAttribute(SESSION_CONFIGURATION, sessionConfiguration); WebXmlParser.parseWebXml(sessionConfiguration, context); sessionConfiguration.initializeFrom(new SessionConfiguration.AttributeProvider() { @Override public String getAttribute(String key) { return context.getInitParameter(key); } @Override public Object source() { return context.getContextPath(); } }); if (sessionConfiguration.getTrueNamespace() == null) { sessionConfiguration.setNamespace(context.getContextPath()); } } return sessionConfiguration; }  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 testInitConf() { when(servletContext.getContextPath()).thenReturn("my-context"); SessionConfiguration configuration = SessionHelpers.initConf(servletContext); assertNotNull(configuration); verify(servletContext).setAttribute(SessionHelpers.SESSION_CONFIGURATION, configuration); assertEquals("my-context", configuration.getNamespace()); }
@Test public void testInitConfFromServletContext() { SessionConfiguration sc = new SessionConfiguration(); when(servletContext.getAttribute(SessionHelpers.SESSION_CONFIGURATION)).thenReturn(sc); SessionConfiguration configuration = SessionHelpers.initConf(servletContext); assertEquals(sc, configuration); verify(servletContext, never()).setAttribute(Mockito.eq(SessionHelpers.SESSION_CONFIGURATION), any()); }