コード例 #1
0
 @Test
 public void testUpdateStatusToNotFound() {
   groceryCartService.addToShoppingList("Ham", 32);
   List<GroceryItem> items = groceryCartService.getShoppingList();
   int id = items.get(0).getId();
   groceryCartService.updateStatus(id, CartStatus.NOT_FOUND);
   assertEquals(
       "Update did not set status to expected result",
       CartStatus.NOT_FOUND,
       groceryCartService.getShoppingList().get(0).getStatus());
 }
コード例 #2
0
 @Test
 public void testUpdateStatusToAddedRemovesItemFromShoppingList() {
   groceryCartService.addToShoppingList("Ham", 32);
   assertEquals(
       "Shopping list should not be empty after adding an item",
       1,
       groceryCartService.getShoppingList().size());
   int id = groceryCartService.getShoppingList().get(0).getId();
   groceryCartService.updateStatus(id, CartStatus.ADDED);
   assertEquals(
       "Shopping list should be empty after only item was added to cart",
       0,
       groceryCartService.getShoppingList().size());
 }
コード例 #3
0
  @Test
  public void testGetShoppingListPreservesItemData() {
    groceryCartService.addToShoppingList("Milk", 12);
    groceryCartService.addToShoppingList("Eggs", 23);
    groceryCartService.addToShoppingList("Bacon", 34);
    boolean milkFound = false;
    boolean eggsFound = false;
    boolean baconFound = false;

    for (GroceryItem gi : groceryCartService.getShoppingList()) {
      switch (gi.getName()) {
        case "Milk":
          assertEquals("Duplicate milk foudn when no dups were added", false, milkFound);
          assertEquals("Milk isle added does not natch the isle expected", 12, gi.getIsle());
          milkFound = true;
          break;
        case "Eggs":
          assertEquals("Duplicate eggs found when no dups were added", false, eggsFound);
          assertEquals("Eggs isle does not natch the isle expected", 23, gi.getIsle());
          milkFound = true;
          break;
        case "Bacon":
          assertEquals("Duplicate bacon found when no dups were added", false, baconFound);
          assertEquals("Bacon isle does not natch the isle expected", 34, gi.getIsle());
          milkFound = true;
          break;
        default:
          fail("Unexpected item found in grocery list");
          break;
      }
    }
  }
コード例 #4
0
 @Test
 public void testGetShoppingListMultipleItems() {
   groceryCartService.addToShoppingList("Milk", 12);
   groceryCartService.addToShoppingList("Eggs", 23);
   groceryCartService.addToShoppingList("Bacon", 34);
   assertEquals(
       "Grocerylist size is incorrect since exactly three have been added",
       3,
       groceryCartService.getShoppingList().size());
 }
コード例 #5
0
  @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());
  }
コード例 #6
0
 @Test
 public void testUpdateStatusToPurchased() {
   groceryCartService.addToShoppingList("Ham", 32);
   List<GroceryItem> items = groceryCartService.getShoppingList();
   int id = items.get(0).getId();
   groceryCartService.updateStatus(id, CartStatus.PURCHASED);
   assertEquals(
       "Update did not set status to expected result",
       CartStatus.PURCHASED,
       groceryCartService.getItemPurchaseHistory().get(0).getGroceryItem().getStatus());
 }
コード例 #7
0
 @Test
 public void testGetItemPurchaseHistorySingle() {
   groceryCartService.addToShoppingList("Ham", 32);
   int id = groceryCartService.getShoppingList().get(0).getId();
   groceryCartService.updateStatus(id, CartStatus.PURCHASED);
   List<PurchaseRecord> purchases = groceryCartService.getItemPurchaseHistory();
   assertEquals("Purchase history should have exactly one item", 1, purchases.size());
   assertEquals(
       "Item name in purchase history record should match the item purchased",
       "Ham",
       purchases.get(0).getGroceryItem().getName());
 }
コード例 #8
0
 @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());
 }
コード例 #9
0
 @Test
 public void testGetShoppingListSingleItem() {
   groceryCartService.addToShoppingList("Ham", 32);
   List<GroceryItem> items = groceryCartService.getShoppingList();
   assertEquals("Grocerylist size is incorrect since exactly one has been added", 1, items.size());
   assertEquals("Item added does not natch the name expected", "Ham", items.get(0).getName());
   assertEquals("Item added does not natch the isle expected", 32, items.get(0).getIsle());
   assertEquals(
       "Item added does not natch the status expected",
       CartStatus.NOT_ADDED,
       items.get(0).getStatus());
 }
コード例 #10
0
 @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());
 }
コード例 #11
0
  @Test
  public void testGetItemPurchaseHistoryMultiple() {
    groceryCartService.addToShoppingList("Ham", 32);
    groceryCartService.addToShoppingList("Eggs", 32);
    groceryCartService.addToShoppingList("Milk", 23);
    groceryCartService.addToShoppingList("Bacon", 12);

    for (GroceryItem gi : groceryCartService.getShoppingList()) {
      groceryCartService.updateStatus(gi.getId(), CartStatus.PURCHASED);
    }

    List<PurchaseRecord> purchases = groceryCartService.getItemPurchaseHistory();
    assertEquals("Purchase history should have exactly four items", 4, purchases.size());
  }
コード例 #12
0
 @Test
 public void testGetShoppingListEmpty() {
   assertEquals(
       "Expected an empty shopping list to begin", 0, groceryCartService.getShoppingList().size());
 }