001    package com.mockrunner.mock.web;
002    
003    import java.io.IOException;
004    
005    import javax.servlet.RequestDispatcher;
006    import javax.servlet.ServletException;
007    import javax.servlet.ServletRequest;
008    import javax.servlet.ServletResponse;
009    
010    /**
011     * Mock implementation of <code>RequestDispatcher</code>.
012     */
013    public class MockRequestDispatcher implements RequestDispatcher
014    {
015        private ServletRequest forwardedRequest;
016        private ServletResponse forwardedResponse;
017        private ServletRequest includedRequest;
018        private ServletResponse includedResponse;
019        private String path;
020        
021        /**
022         * Sets the path for this <code>RequestDispatcher</code>.
023         * @param path the path
024         */
025        public void setPath(String path)
026        {
027            this.path = path;
028        }
029       
030        /**
031         * Returns the name or path used to retrieve this <code>RequestDispatcher</code>.
032         * @return the name or path used to retrieve this <code>RequestDispatcher</code>
033         */
034        public String getPath()
035        {
036            return path;
037        }
038    
039        public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException
040        {
041            forwardedRequest = request;
042            forwardedResponse = response;
043        }
044    
045        public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
046        {
047            includedRequest = request;
048            includedResponse = response;
049        }
050        
051        public ServletRequest getForwardedRequest()
052        {
053            return forwardedRequest;
054        }
055    
056        public ServletResponse getForwardedResponse()
057        {
058            return forwardedResponse;
059        }
060    
061        public ServletRequest getIncludedRequest()
062        {
063            return includedRequest;
064        }
065    
066        public ServletResponse getIncludedResponse()
067        {
068            return includedResponse;
069        }
070    }