### Question:
PluginHttpRequestWrapper extends HttpServletRequestWrapper { @Override public HttpSession getSession() { return this.getSession(true); } PluginHttpRequestWrapper(HttpServletRequest request, BaseServletModuleDescriptor<?> descriptor); String getServletPath(); String getPathInfo(); @Override HttpSession getSession(); @Override HttpSession getSession(final boolean create);  }### Answer:
@Test public void testGetSession() throws Exception { Mock mockSession = new Mock(HttpSession.class); mockSession.matchAndReturn("getAttribute", "foo", "bar"); HttpSession realSession = (HttpSession) mockSession.proxy(); Mock mockWrappedRequest = new Mock(HttpServletRequest.class); mockWrappedRequest.matchAndReturn("getPathInfo", null); mockWrappedRequest.matchAndReturn("getSession", true, realSession); PluginHttpRequestWrapper request = new PluginHttpRequestWrapper((HttpServletRequest) mockWrappedRequest.proxy(), null); HttpSession wrappedSession = request.getSession(); assertTrue(wrappedSession instanceof PluginHttpSessionWrapper); assertEquals("bar", wrappedSession.getAttribute("foo")); }
@Test public void testGetSessionFalse() throws Exception { Mock mockWrappedRequest = new Mock(HttpServletRequest.class); mockWrappedRequest.matchAndReturn("getPathInfo", null); mockWrappedRequest.matchAndReturn("getSession", false, null); PluginHttpRequestWrapper request = new PluginHttpRequestWrapper((HttpServletRequest) mockWrappedRequest.proxy(), null); assertNull(request.getSession(false)); }
@Test public void testGetSessionTrue() throws Exception { Mock mockSession = new Mock(HttpSession.class); mockSession.matchAndReturn("getAttribute", "foo", "bar"); HttpSession realSession = (HttpSession) mockSession.proxy(); Mock mockWrappedRequest = new Mock(HttpServletRequest.class); mockWrappedRequest.matchAndReturn("getPathInfo", null); mockWrappedRequest.matchAndReturn("getSession", true, realSession); PluginHttpRequestWrapper request = new PluginHttpRequestWrapper((HttpServletRequest) mockWrappedRequest.proxy(), null); HttpSession wrappedSession = request.getSession(true); assertTrue(wrappedSession instanceof PluginHttpSessionWrapper); assertEquals("bar", wrappedSession.getAttribute("foo")); }