ServletContextImpl implements ServletContext { public HttpSessionImpl createNewSession() { HttpSessionImpl session = new HttpSessionImpl(StringUtilities.generateRandom(), System.currentTimeMillis()); session.setServletContext(this); LOGGER.log(Level.FINE, "Created a new session {0}", new Object[]{session.getId()}); return session; } ServletContextImpl(final String contextPath,
                              final List<ServletMapping> servletMappings,
                              final List<FilterMapping> filterMappings,
                              final Map<String, Object> attributes,
                              final ServerConfig serverConfig,
                              final SessionStorage sessionStorage); @Override String getMimeType(final String file); @Override void setAttribute(final String name, final Object value); @Override Object getAttribute(final String name); @Override Enumeration getAttributeNames(); HttpSessionImpl getSession(final String id); HttpSessionImpl createNewSession(); void handleSession(final HttpSessionImpl session, final HttpServletResponseImpl response); @Override List<ServletMapping> getServletMappings(); @Override List<FilterMapping> getFilterMappings(); @Override String getContextPath(); static final int MAX_AGE_IN_PAST; }
@Test public void shouldCreateSessionWithCorrectContext() { HttpSessionImpl session = servletContext.createNewSession(); assertThat(session, is(not(nullValue()))); assertThat(session.getServletContext(), is((ServletContext) servletContext)); }