@Test
public void testNewSessionIdCreatedIfSessionWasInvalidated() {

  HttpServletRequest wrappedSimple = mock(HttpServletRequest.class);
  RepositoryBackedHttpSession invalidSession = mock(RepositoryBackedHttpSession.class);
  RepositoryBackedHttpSession newSession = mock(RepositoryBackedHttpSession.class);
  when(newSession.getId()).thenReturn(NEW_SESSION_ID);
  when(invalidSession.getId()).thenReturn(SESSION_ID);
  when(invalidSession.isValid()).thenReturn(false);
  HttpRequestWrapper wrappedHttpRequestWrapper = spy(new HttpRequestWrapper(wrappedSimple, servletContext));
  wrappedHttpRequestWrapper.session = invalidSession;
  HttpServletRequest wrappedComplex = new HttpServletRequestWrapper(wrappedHttpRequestWrapper);
  HttpRequestWrapper req = new HttpRequestWrapper(wrappedComplex, servletContext);
  when(sessionManager.getSession(req, true, new SessionTracking.IdAndSource(SESSION_ID, false))).thenReturn(invalidSession);
  when(sessionManager.getSession(req, true, null)).thenReturn(newSession);
  RepositoryBackedHttpSession session2 = req.getSession();
  Assert.assertNotNull(session2);
  assertEquals(NEW_SESSION_ID, session2.getId());
}