SessionHelpers { public void commitRequest(ServletRequest request, ServletRequest oldRequest) throws IOException { if (request != oldRequest && request instanceof HttpRequestWrapper) { HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper)request; try { httpRequestWrapper.commit(); if (httpRequestWrapper.getResponse() != null) { httpRequestWrapper.getResponse().flushBuffer(); } } catch (Exception e) { logger.error("An exception occured while commiting the session.", e); throw e; } finally { request.setAttribute(REQUEST_WRAPPED_ATTRIBUTE, httpRequestWrapper.getEmbeddedRequest()); } } }  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 testCommitRequest() throws IOException { HttpRequestWrapper request = mock(HttpRequestWrapper.class); when(request.getServletContext()).thenReturn(servletContext); ServletRequest oldRequest = mock(ServletRequest.class); SessionHelpersFacade.commitRequest(request, oldRequest, null); verify(request).commit(); }
@Test public void testDontCommitNonReWrappedRequest() throws IOException { HttpRequestWrapper request = mock(HttpRequestWrapper.class); when(request.getServletContext()).thenReturn(servletContext); SessionHelpersFacade.commitRequest(request, request, null); verify(request, never()).commit(); }
@Test public void testCommitReWrappedRequest() throws IOException { HttpRequestWrapper oldRequest = mock(HttpRequestWrapper.class); HttpRequestWrapper request = mock(HttpRequestWrapper.class); when(request.getServletContext()).thenReturn(servletContext); SessionHelpersFacade.commitRequest(request, oldRequest, null); verify(request).commit(); verify(oldRequest, never()).commit(); }
@Test public void testDontCommitNonWrappped() throws IOException { ServletRequest request = mock(ServletRequest.class); when(request.getServletContext()).thenReturn(servletContext); HttpRequestWrapper oldRequest = mock(HttpRequestWrapper.class); SessionHelpersFacade.commitRequest(request, oldRequest, null); verify(oldRequest, never()).commit(); }