HttpRequestWrapper extends HttpServletRequestWrapper implements RequestWithSession { @Override public String changeSessionId() { retrieveSessionIfNeeded(false); if (session == null) { throw new IllegalStateException("There is no session associated with the request."); } manager.switchSessionId(session); return session.getId(); } HttpRequestWrapper(HttpServletRequest req, ServletContext servletContext); @Override RepositoryBackedHttpSession getSession(); @Override RepositoryBackedHttpSession getSession(boolean create); SessionManager getManager(); HttpResponseWrapper getResponse(); void setResponse(HttpResponseWrapper response); void commit(); @Override RepositoryBackedHttpSession getRepositoryBackedSession(boolean create); @Override ServletContext getServletContext(); HttpRequestWrapper getEmbeddedRequest(); boolean isPropagateOnCreate(); void setPropagateOnCreate(boolean propagate); @Override boolean isIdRetrieved(); @Override void setRequestedSessionId(String id, boolean isFromCookie); @Override String getRequestedSessionId(); @Override boolean isRequestedSessionIdFromCookie(); @Override boolean isRequestedSessionIdFromURL(); @Override boolean isRequestedSessionIdFromUrl(); @Override boolean isRequestedSessionIdValid(); @Override boolean isRepositoryChecked(); @Override void repositoryChecked(); String encodeURL(String url); @Override String changeSessionId();  }
@Test(expected=IllegalStateException.class) public void testChangeSessionIdNoSession() { HttpServletRequest wrappedSimple = mock(HttpServletRequest.class); HttpRequestWrapper req = new HttpRequestWrapper(wrappedSimple, servletContext); req.changeSessionId(); }
@Test public void testChangeSessionId() { HttpServletRequest wrappedSimple = mock(HttpServletRequest.class); HttpRequestWrapper req = new HttpRequestWrapper(wrappedSimple, servletContext); RepositoryBackedHttpSession session = mock(RepositoryBackedHttpSession.class); when(sessionManager.getSession(req, false, null)).thenReturn(session); when(session.getId()).thenReturn(SESSION_ID); String id = req.changeSessionId(); assertEquals(SESSION_ID, id); verify(sessionManager).switchSessionId(session); verify(session).getId(); }