diff --git a/src/main/java/verkocht/model/CookingBook.java b/src/main/java/verkocht/model/CookingBook.java index d149722..f46293a 100644 --- a/src/main/java/verkocht/model/CookingBook.java +++ b/src/main/java/verkocht/model/CookingBook.java @@ -10,6 +10,10 @@ public class CookingBook { private static List allRecipes; private List allIngredients; + public List getAllRecipes() { + return allRecipes; + } + public CookingBook() { // Schnitzel Recipe meatRecipe = new Recipe(); @@ -64,25 +68,25 @@ public Recipe findByName(String name) { * @param category * @return */ - public static List findByCategory(Category category) { + public List findByCategory(Category category) { List a = null; switch (category) { case MEAT: - for (int i = 0; i < allRecipes.size(); i++) { + for (int i = 0; i <= allRecipes.size(); i++) { if(allRecipes.get(i).getCategory() == category.MEAT) { a.add(allRecipes.get(i)); } } return a; case VEGETARIAN: - for (int i = 0; i < allRecipes.size(); i++) { + for (int i = 0; i <= allRecipes.size(); i++) { if(allRecipes.get(i).getCategory() == category.VEGETARIAN) { a.add(allRecipes.get(i)); } } return a; case VEGAN: - for (int i = 0; i < allRecipes.size(); i++) { + for (int i = 0; i <= allRecipes.size(); i++) { if(allRecipes.get(i).getCategory() == category.VEGAN) { a.add(allRecipes.get(i)); } diff --git a/src/test/java/CookingBookTest.java b/src/test/java/CookingBookTest.java index a14cbae..3509013 100644 --- a/src/test/java/CookingBookTest.java +++ b/src/test/java/CookingBookTest.java @@ -1,13 +1,17 @@ import static org.junit.Assert.*; +import java.util.List; + import org.junit.Test; import verkocht.model.*; public class CookingBookTest { + CookingBook a = new CookingBook(); + List b; @Test public void testFindByCategory() { - // assertTrue(CookingBook.findByCategory(Category.MEAT).get(1).equals(CookingBook.meatRecipes.get(1))); + b = (List) a.getAllRecipes().get(1); + assertEquals(a.findByCategory(Category.MEAT),b); } - }