import java.util.Arrays;
import java.util.List;

import org.junit.*;
import static org.junit.Assert.*;

public class DishTest {

  @Rule
  public DatabaseRule database = new DatabaseRule();

  @Test
  public void equals_returnsTrueIfSameName() {
    Dish firstDish = new Dish("Cheeseburger");
    firstDish.save();
    Dish secondDish = new Dish("Cheeseburger");
    secondDish.save();
    assertTrue(firstDish.equals(secondDish));
  }

  @Test
  public void all_emptyAtFirst() {
    assertEquals(Dish.all().size(), 0);
  }

  @Test
  public void dish_instantiatesNameAndFindsItInListOfDishes() {
    Dish dish = new Dish("Cheeseburger");
    dish.save();
    assertEquals("Cheeseburger", Dish.find(dish.getId()).getName());
  }

  @Test
  public void delete_deletesADish() {
    Dish dish = new Dish("Cheeseburger");
    dish.save();
    Dish anotherDish = new Dish("Turkey Burger");
    anotherDish.save();
    dish.delete();
    assertEquals(1, Dish.all().size());
  }

  @Test
  public void update_updateWorksProperly() {
    Dish dish = new Dish("Cheeseburger");
    dish.save();
    dish.update("Turkey Burger");
    assertEquals(dish.getName(), "Turkey Burger");
  }

  @Test
  public void addIngredient_addsIngredientToDishesIngredientsTable() {
    Dish dish = new Dish("Cheeseburger");
    dish.save();
    Ingredient ingredient = new Ingredient("Ground Beef", "Ounce", 20, 5);
    ingredient.save();
    dish.addIngredient(ingredient.getId(), 8);
    Ingredient[] ingredients = new Ingredient[] {ingredient};
    assertTrue(dish.getAllIngredients().containsAll(Arrays.asList(ingredients)));
  }

  @Test
  public void removeIngredient_removesAnIngredientFromDishesIngredientsTable() {
    Dish dish = new Dish("Cheeseburger");
    dish.save();
    Ingredient ingredient = new Ingredient("Ground Beef", "Ounce", 20, 5);
    ingredient.save();
    dish.addIngredient(ingredient.getId(), 8);
    Ingredient ingredientTwo = new Ingredient("Ground Beef", "Ounce", 20, 5);
    ingredientTwo.save();
    dish.addIngredient(ingredientTwo.getId(), 8);
    dish.removeIngredient(ingredient.getId());
    Ingredient[] ingredients = new Ingredient[] {ingredientTwo};
    assertTrue(dish.getAllIngredients().containsAll(Arrays.asList(ingredients)));
    assertEquals(dish.getAllIngredients().size(), 1);
  }

  @Test
  public void getTimesOrderedToday_getsACountOfDishOrderedToday_2() {
    Dish dishOne = new Dish("Cheeseburger");
    dishOne.save();
    Dish dishTwo = new Dish("Hamburger");
    dishTwo.save();
    Order orderOne = new Order(1, 1, dishOne.getId());
    orderOne.save();
    Order orderTwo = new Order(1, 2, dishOne.getId());
    orderTwo.save();
    Order orderThree = new Order(1, 3, dishTwo.getId());
    orderThree.save();
    assertEquals(dishOne.getTimesOrderedToday(), 2);
  }
}

@@ -2793,11 +2793,461 @@
  2);%0A  %7D
+%0A%0A  @Test%0A  public void hasMissingIngredient_indicatesDishMissingIngredient_true() %7B%0A    Dish dish = new Dish(%22Cheeseburger%22);%0A    dish.save();%0A    Ingredient ingredient = new Ingredient(%22Ground Beef%22, %22Ounce%22, 20, 5);%0A    ingredient.save();%0A    dish.addIngredient(ingredient.getId(), 8);%0A    Inventory inventory = new Inventory(ingredient.getId(), 0);%0A    inventory.save();%0A    assertEquals(true, Dish.find(dish.getId()).hasMissingIngredient());%0A  %7D
 %0A%7D%0A

test hasMissingIngredient method