TestHttpRequestWrapper.java 文件源码

java
阅读 31 收藏 0 点赞 0 评论 0

项目:HttpSessionReplacer 作者:
@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, SESSION_ID)).thenReturn(invalidSession);
  when(sessionManager.getSession(req, true, null)).thenReturn(newSession);
  RepositoryBackedHttpSession session2 = req.getSession();
  Assert.assertNotNull(session2);
  assertEquals(NEW_SESSION_ID, session2.getId());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号