@Test public void testUpdateStatusToAddedRemovesFromCart() { groceryCartService.addToShoppingList("Ham", 32); int id = groceryCartService.getShoppingList().get(0).getId(); groceryCartService.updateStatus(id, CartStatus.ADDED); assertEquals( "Cart should have exactly one item that was added", 1, groceryCartService.getCart().size()); groceryCartService.updateStatus(id, CartStatus.PURCHASED); assertEquals( "Cart should have no items since only item was purchased", 0, groceryCartService.getCart().size()); }
@Test public void testGetCartMultipleItems() { groceryCartService.addToShoppingList("Ham", 32); groceryCartService.addToShoppingList("Eggs", 21); for (GroceryItem gi : groceryCartService.getShoppingList()) { groceryCartService.updateStatus(gi.getId(), CartStatus.ADDED); } assertEquals("Cart should have exactly two items", 2, groceryCartService.getCart().size()); }
@Test public void testUpdateStatusToAdded() { groceryCartService.addToShoppingList("Ham", 32); List<GroceryItem> items = groceryCartService.getShoppingList(); int id = items.get(0).getId(); groceryCartService.updateStatus(id, CartStatus.ADDED); assertEquals( "Update did not set status to expected result", CartStatus.ADDED, groceryCartService.getCart().get(0).getStatus()); }
@Test public void testGetCartSingleItem() { groceryCartService.addToShoppingList("Ham", 32); groceryCartService.updateStatus( groceryCartService.getShoppingList().get(0).getId(), CartStatus.ADDED); List<GroceryItem> items = groceryCartService.getCart(); assertEquals("Cart should have exactly one item that was added", 1, items.size()); assertEquals("Item in cart does not have correct name", "Ham", items.get(0).getName()); assertEquals("Item in cart does not have correct isle", 32, items.get(0).getIsle()); assertEquals( "Item in cart does not have correct status", CartStatus.ADDED, items.get(0).getStatus()); }
@Test public void testGetCartEmpty() { assertEquals("Expected an empty cart to begin", 0, groceryCartService.getCart().size()); }