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

📄 testcartview.java~101~

📁 购物车模块实例。购物车模块可以浏览商品类别;可以根据商品类别浏览商品信息;可以购买商品;可以查看购物车的商品;可以修改购买商品的数量和删除购买的商品。
💻 JAVA~101~
字号:
package cartservlet;

import org.apache.cactus.*;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import data.*;

public class TestCartView extends ServletTestCase {
  private CartView cartView = null;

  public TestCartView(String name) {
    super(name);
  }

  protected void setUp() throws Exception {
    cartView = new CartView();
    //初始化ServletContext对象
    cartView.init(config);
    request.setCharacterEncoding("GBK");
    super.setUp();
  }

  protected void tearDown() throws Exception {
    cartView = null;
    super.tearDown();
  }

  //为doPost1方法传入参数的方法
  public void beginDoPost1(WebRequest theRequest) {
    //通过WebRequest类设置传入参数
    theRequest.addParameter("action", "商品浏览窗口", WebRequest.POST_METHOD);
    theRequest.addParameter("name", "", WebRequest.POST_METHOD);
  }
  //测试是否可以正确处理顾客名字为空的登陆
  public void testDoPost1() throws ServletException, IOException {
    //测试是否正确设置action参数和name参数
    assertEquals("商品浏览窗口", request.getParameter("action"));
    assertEquals("", request.getParameter("name"));
    cartView.doPost(request, response);
    this.assertNotNull(request.getAttribute("infor"));
    //不能登陆,购物车对象应该为空
    this.assertNull(session.getAttribute("cart"));
  }
  //为doPost2方法传入参数的方法
  public void beginDoPost2(WebRequest theRequest) {
    //通过WebRequest类设置传入参数
    theRequest.addParameter("action", "商品浏览窗口", WebRequest.POST_METHOD);
    theRequest.addParameter("name", "jack", WebRequest.POST_METHOD);
  }
  //测试是否可以正确处理顾客名字不为空的登陆
  public void testDoPost2() throws ServletException, IOException {
    //测试是否正确设置action参数和name参数
    assertEquals("商品浏览窗口", request.getParameter("action"));
    assertEquals("jack", request.getParameter("name"));
    cartView.doPost(request, response);
    //正确登陆,购物车对象不为空
    this.assertNotNull(session.getAttribute("cart"));
    Cart cart = (Cart)session.getAttribute("cart");
    this.assertEquals("顾客名字应该是jack", "jack", cart.getCustomer());
  }
}

⌨️ 快捷键说明

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