Skip to content

Commit

Permalink
#28 sending new version of method
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Nov 24, 2018
1 parent 92531cc commit 8c13891
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/main/java/verkocht/model/CookingBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public class CookingBook {
private static List<Recipe> allRecipes;
private List<Ingredient> allIngredients;

public List<Recipe> getAllRecipes() {
return allRecipes;
}

public CookingBook() {
// Schnitzel
Recipe meatRecipe = new Recipe();
Expand Down Expand Up @@ -64,25 +68,25 @@ public Recipe findByName(String name) {
* @param category
* @return
*/
public static List<Recipe> findByCategory(Category category) {
public List<Recipe> findByCategory(Category category) {
List<Recipe> 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));
}
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/CookingBookTest.java
Original file line number Diff line number Diff line change
@@ -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<Recipe> b;
@Test
public void testFindByCategory() {
// assertTrue(CookingBook.findByCategory(Category.MEAT).get(1).equals(CookingBook.meatRecipes.get(1)));
b = (List<Recipe>) a.getAllRecipes().get(1);
assertEquals(a.findByCategory(Category.MEAT),b);
}

}

0 comments on commit 8c13891

Please sign in to comment.