public String execute() { // Get the index of the item to remove int itemIndex = Integer.parseInt(request.getParameter("item")); HttpSession session = request.getSession(); // Get the cart ShoppingCart cart = (ShoppingCart) session.getAttribute("ShoppingCart"); cart.removeItem(itemIndex); return SUCCESS; }
@Test public void testRemoveItem() throws Exception { cart.removeItem("9781430216407"); assertEquals(1, cart.getItems().size()); assertNull(cart.getItems().get("9781430216407")); }