1   package org.jmage.tags;
2   
3   import org.jmock.cglib.Mock;
4   import org.jmock.cglib.MockObjectTestCase;
5   
6   import javax.servlet.http.HttpServletRequest;
7   import javax.servlet.jsp.JspException;
8   import javax.servlet.jsp.JspWriter;
9   import javax.servlet.jsp.PageContext;
10  
11  /***
12   * GenericTagHandlerTests
13   */
14  public abstract class GenericTagHandlerTests extends MockObjectTestCase {
15      protected Mock mockHttpServletRequest;
16      protected Mock mockPageContext;
17      protected Mock mockJspWriter;
18      protected JmageTagHandler jmageTagHandler;
19  
20      protected void setUp() throws Exception {
21          super.setUp();
22          mockHttpServletRequest = new Mock(HttpServletRequest.class);
23          mockPageContext = new Mock(PageContext.class);
24          mockJspWriter = new Mock(MyDummyJspWriter.class);
25      }
26  
27      public void testDoEndTag() throws JspException {
28          this.setExpectations();
29          assertEquals(0, jmageTagHandler.doStartTag());
30          assertEquals(6, jmageTagHandler.doEndTag());
31      }
32  
33      protected void setExpectations() {
34          mockPageContext.expects(once()).method("getRequest").will(returnValue((HttpServletRequest) mockHttpServletRequest.proxy()));
35          mockPageContext.expects(once()).method("getOut").will(returnValue((JspWriter) mockJspWriter.proxy()));
36          mockHttpServletRequest.expects(once()).method("getContextPath").will(returnValue("http://host.org/context"));
37          mockHttpServletRequest.expects(atLeastOnce()).method("getHeader").with(eq("user-agent")).will(returnValue("windows msie 6.0"));
38          mockJspWriter.expects(once()).method("print").with(eq(this.getTagResult())).isVoid();
39      }
40  
41      protected abstract String getTagResult();
42  }