⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mockpagecontext.java

📁 软件测试经典书籍<<Junit in action>>里的源代码。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package junitbook.pages;

import mockmaker.ReturnValues;
import mockmaker.VoidReturnValues;
import mockmaker.ExceptionalReturnValue;
import com.mockobjects.*;

import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
public class MockPageContext extends PageContext{
   private ExpectationCounter myInitializeCalls = new ExpectationCounter("javax.servlet.jsp.PageContext InitializeCalls");
   private ReturnValues myActualInitializeReturnValues = new VoidReturnValues(false);
   private ExpectationList myInitializeParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext javax.servlet.Servlet");
   private ExpectationList myInitializeParameter1Values = new ExpectationList("javax.servlet.jsp.PageContext javax.servlet.ServletRequest");
   private ExpectationList myInitializeParameter2Values = new ExpectationList("javax.servlet.jsp.PageContext javax.servlet.ServletResponse");
   private ExpectationList myInitializeParameter3Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationList myInitializeParameter4Values = new ExpectationList("javax.servlet.jsp.PageContext boolean");
   private ExpectationList myInitializeParameter5Values = new ExpectationList("javax.servlet.jsp.PageContext int");
   private ExpectationList myInitializeParameter6Values = new ExpectationList("javax.servlet.jsp.PageContext boolean");
   private ExpectationCounter myReleaseCalls = new ExpectationCounter("javax.servlet.jsp.PageContext ReleaseCalls");
   private ReturnValues myActualReleaseReturnValues = new VoidReturnValues(false);
   private ExpectationCounter mySetAttributeStringObjectCalls = new ExpectationCounter("javax.servlet.jsp.PageContext SetAttributeStringObjectCalls");
   private ReturnValues myActualSetAttributeStringObjectReturnValues = new VoidReturnValues(false);
   private ExpectationList mySetAttributeStringObjectParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationList mySetAttributeStringObjectParameter1Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.Object");
   private ExpectationCounter mySetAttributeStringObjectIntCalls = new ExpectationCounter("javax.servlet.jsp.PageContext SetAttributeStringObjectIntCalls");
   private ReturnValues myActualSetAttributeStringObjectIntReturnValues = new VoidReturnValues(false);
   private ExpectationList mySetAttributeStringObjectIntParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationList mySetAttributeStringObjectIntParameter1Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.Object");
   private ExpectationList mySetAttributeStringObjectIntParameter2Values = new ExpectationList("javax.servlet.jsp.PageContext int");
   private ExpectationCounter myGetAttributeStringCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetAttributeStringCalls");
   private ReturnValues myActualGetAttributeStringReturnValues = new ReturnValues(false);
   private ExpectationList myGetAttributeStringParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationCounter myGetAttributeStringIntCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetAttributeStringIntCalls");
   private ReturnValues myActualGetAttributeStringIntReturnValues = new ReturnValues(false);
   private ExpectationList myGetAttributeStringIntParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationList myGetAttributeStringIntParameter1Values = new ExpectationList("javax.servlet.jsp.PageContext int");
   private ExpectationCounter myFindAttributeCalls = new ExpectationCounter("javax.servlet.jsp.PageContext FindAttributeCalls");
   private ReturnValues myActualFindAttributeReturnValues = new ReturnValues(false);
   private ExpectationList myFindAttributeParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationCounter myRemoveAttributeStringCalls = new ExpectationCounter("javax.servlet.jsp.PageContext RemoveAttributeStringCalls");
   private ReturnValues myActualRemoveAttributeStringReturnValues = new VoidReturnValues(false);
   private ExpectationList myRemoveAttributeStringParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationCounter myRemoveAttributeStringIntCalls = new ExpectationCounter("javax.servlet.jsp.PageContext RemoveAttributeStringIntCalls");
   private ReturnValues myActualRemoveAttributeStringIntReturnValues = new VoidReturnValues(false);
   private ExpectationList myRemoveAttributeStringIntParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationList myRemoveAttributeStringIntParameter1Values = new ExpectationList("javax.servlet.jsp.PageContext int");
   private ExpectationCounter myGetAttributesScopeCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetAttributesScopeCalls");
   private ReturnValues myActualGetAttributesScopeReturnValues = new ReturnValues(false);
   private ExpectationList myGetAttributesScopeParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationCounter myGetAttributeNamesInScopeCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetAttributeNamesInScopeCalls");
   private ReturnValues myActualGetAttributeNamesInScopeReturnValues = new ReturnValues(false);
   private ExpectationList myGetAttributeNamesInScopeParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext int");
   private ExpectationCounter myGetOutCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetOutCalls");
   private ReturnValues myActualGetOutReturnValues = new ReturnValues(false);
   private ExpectationCounter myGetSessionCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetSessionCalls");
   private ReturnValues myActualGetSessionReturnValues = new ReturnValues(false);
   private ExpectationCounter myGetPageCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetPageCalls");
   private ReturnValues myActualGetPageReturnValues = new ReturnValues(false);
   private ExpectationCounter myGetRequestCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetRequestCalls");
   private ReturnValues myActualGetRequestReturnValues = new ReturnValues(false);
   private ExpectationCounter myGetResponseCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetResponseCalls");
   private ReturnValues myActualGetResponseReturnValues = new ReturnValues(false);
   private ExpectationCounter myGetExceptionCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetExceptionCalls");
   private ReturnValues myActualGetExceptionReturnValues = new ReturnValues(false);
   private ExpectationCounter myGetServletConfigCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetServletConfigCalls");
   private ReturnValues myActualGetServletConfigReturnValues = new ReturnValues(false);
   private ExpectationCounter myGetServletContextCalls = new ExpectationCounter("javax.servlet.jsp.PageContext GetServletContextCalls");
   private ReturnValues myActualGetServletContextReturnValues = new ReturnValues(false);
   private ExpectationCounter myForwardCalls = new ExpectationCounter("javax.servlet.jsp.PageContext ForwardCalls");
   private ReturnValues myActualForwardReturnValues = new VoidReturnValues(false);
   private ExpectationList myForwardParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationCounter myIncludeCalls = new ExpectationCounter("javax.servlet.jsp.PageContext IncludeCalls");
   private ReturnValues myActualIncludeReturnValues = new VoidReturnValues(false);
   private ExpectationList myIncludeParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.String");
   private ExpectationCounter myHandlePageExceptionExceptionCalls = new ExpectationCounter("javax.servlet.jsp.PageContext HandlePageExceptionExceptionCalls");
   private ReturnValues myActualHandlePageExceptionExceptionReturnValues = new VoidReturnValues(false);
   private ExpectationList myHandlePageExceptionExceptionParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.Exception");
   private ExpectationCounter myHandlePageExceptionThrowableCalls = new ExpectationCounter("javax.servlet.jsp.PageContext HandlePageExceptionThrowableCalls");
   private ReturnValues myActualHandlePageExceptionThrowableReturnValues = new VoidReturnValues(false);
   private ExpectationList myHandlePageExceptionThrowableParameter0Values = new ExpectationList("javax.servlet.jsp.PageContext java.lang.Throwable");
   private ExpectationCounter myPushBodyCalls = new ExpectationCounter("javax.servlet.jsp.PageContext PushBodyCalls");
   private ReturnValues myActualPushBodyReturnValues = new ReturnValues(false);
   private ExpectationCounter myPopBodyCalls = new ExpectationCounter("javax.servlet.jsp.PageContext PopBodyCalls");
   private ReturnValues myActualPopBodyReturnValues = new ReturnValues(false);
   public void setExpectedInitializeCalls(int calls){
      myInitializeCalls.setExpected(calls);
   }
   public void addExpectedInitializeValues(Servlet arg0, ServletRequest arg1, ServletResponse arg2, String arg3, boolean arg4, int arg5, boolean arg6){
      myInitializeParameter0Values.addExpected(arg0);
      myInitializeParameter1Values.addExpected(arg1);
      myInitializeParameter2Values.addExpected(arg2);
      myInitializeParameter3Values.addExpected(arg3);
      myInitializeParameter4Values.addExpected(new Boolean(arg4));
      myInitializeParameter5Values.addExpected(new Integer(arg5));
      myInitializeParameter6Values.addExpected(new Boolean(arg6));
   }
   public void initialize(Servlet arg0, ServletRequest arg1, ServletResponse arg2, String arg3, boolean arg4, int arg5, boolean arg6) throws IOException, IllegalStateException, IllegalArgumentException{
      myInitializeCalls.inc();
      myInitializeParameter0Values.addActual(arg0);
      myInitializeParameter1Values.addActual(arg1);
      myInitializeParameter2Values.addActual(arg2);
      myInitializeParameter3Values.addActual(arg3);
      myInitializeParameter4Values.addActual(new Boolean(arg4));
      myInitializeParameter5Values.addActual(new Integer(arg5));
      myInitializeParameter6Values.addActual(new Boolean(arg6));
      Object nextReturnValue = myActualInitializeReturnValues.getNext();
      if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof IOException)
          throw (IOException)((ExceptionalReturnValue)nextReturnValue).getException();
      if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof IllegalStateException)
          throw (IllegalStateException)((ExceptionalReturnValue)nextReturnValue).getException();
      if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof IllegalArgumentException)
          throw (IllegalArgumentException)((ExceptionalReturnValue)nextReturnValue).getException();
      if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
          throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
   }
   public void setupExceptionInitialize(Throwable arg){
      myActualInitializeReturnValues.add(new ExceptionalReturnValue(arg));
   }
   public void setExpectedReleaseCalls(int calls){
      myReleaseCalls.setExpected(calls);
   }
   public void release(){
      myReleaseCalls.inc();
      Object nextReturnValue = myActualReleaseReturnValues.getNext();
      if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
          throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
   }
   public void setupExceptionRelease(Throwable arg){
      myActualReleaseReturnValues.add(new ExceptionalReturnValue(arg));
   }
   public void setExpectedSetAttributeStringObjectCalls(int calls){
      mySetAttributeStringObjectCalls.setExpected(calls);
   }
   public void addExpectedSetAttributeStringObjectValues(String arg0, Object arg1){
      mySetAttributeStringObjectParameter0Values.addExpected(arg0);
      mySetAttributeStringObjectParameter1Values.addExpected(arg1);
   }
   public void setAttribute(String arg0, Object arg1){
      mySetAttributeStringObjectCalls.inc();
      mySetAttributeStringObjectParameter0Values.addActual(arg0);
      mySetAttributeStringObjectParameter1Values.addActual(arg1);
      Object nextReturnValue = myActualSetAttributeStringObjectReturnValues.getNext();
      if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
          throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
   }
   public void setupExceptionSetAttributeStringObject(Throwable arg){
      myActualSetAttributeStringObjectReturnValues.add(new ExceptionalReturnValue(arg));
   }
   public void setExpectedSetAttributeStringObjectIntCalls(int calls){
      mySetAttributeStringObjectIntCalls.setExpected(calls);
   }
   public void addExpectedSetAttributeStringObjectIntValues(String arg0, Object arg1, int arg2){
      mySetAttributeStringObjectIntParameter0Values.addExpected(arg0);
      mySetAttributeStringObjectIntParameter1Values.addExpected(arg1);
      mySetAttributeStringObjectIntParameter2Values.addExpected(new Integer(arg2));
   }
   public void setAttribute(String arg0, Object arg1, int arg2){
      mySetAttributeStringObjectIntCalls.inc();
      mySetAttributeStringObjectIntParameter0Values.addActual(arg0);
      mySetAttributeStringObjectIntParameter1Values.addActual(arg1);
      mySetAttributeStringObjectIntParameter2Values.addActual(new Integer(arg2));
      Object nextReturnValue = myActualSetAttributeStringObjectIntReturnValues.getNext();
      if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
          throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
   }
   public void setupExceptionSetAttributeStringObjectInt(Throwable arg){
      myActualSetAttributeStringObjectIntReturnValues.add(new ExceptionalReturnValue(arg));
   }
   public void setExpectedGetAttributeStringCalls(int calls){
      myGetAttributeStringCalls.setExpected(calls);
   }
   public void addExpectedGetAttributeStringValues(String arg0){
      myGetAttributeStringParameter0Values.addExpected(arg0);
   }
   public Object getAttribute(String arg0){
      myGetAttributeStringCalls.inc();
      myGetAttributeStringParameter0Values.addActual(arg0);
      Object nextReturnValue = myActualGetAttributeStringReturnValues.getNext();
      if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
          throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
      return (Object) nextReturnValue;
   }
   public void setupExceptionGetAttributeString(Throwable arg){
      myActualGetAttributeStringReturnValues.add(new ExceptionalReturnValue(arg));
   }
   public void setupGetAttributeString(Object arg){
      myActualGetAttributeStringReturnValues.add(arg);
   }
   public void setExpectedGetAttributeStringIntCalls(int calls){
      myGetAttributeStringIntCalls.setExpected(calls);
   }
   public void addExpectedGetAttributeStringIntValues(String arg0, int arg1){
      myGetAttributeStringIntParameter0Values.addExpected(arg0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -