diff --git a/client/src/main/java/client/scenes/recipe/IngredientListCell.java b/client/src/main/java/client/scenes/recipe/IngredientListCell.java index 749c635..c4c0d25 100644 --- a/client/src/main/java/client/scenes/recipe/IngredientListCell.java +++ b/client/src/main/java/client/scenes/recipe/IngredientListCell.java @@ -55,7 +55,7 @@ public class IngredientListCell extends OrderedEditableListCellnull such that it can be updated @@ -37,7 +38,7 @@ public class DefaultValueFactory { */ public static FormalIngredient getDefaultFormalIngredient() { return new FormalIngredient( - new Ingredient(0L, "default ingredient", 0., 0., 0.), + defaultIngredient, 0.0, Unit.GRAMME.suffix ); @@ -50,8 +51,7 @@ public class DefaultValueFactory { */ public static VagueIngredient getDefaultVagueIngredient() { return new VagueIngredient( - new Ingredient(null, - "default ingredient", 0., 0., 0.), + defaultIngredient, "Some"); } } diff --git a/client/src/test/java/client/ServerUtilsTest.java b/client/src/test/java/client/ServerUtilsTest.java index 47e4786..74c92c7 100644 --- a/client/src/test/java/client/ServerUtilsTest.java +++ b/client/src/test/java/client/ServerUtilsTest.java @@ -1,7 +1,11 @@ package client; import client.utils.ServerUtils; +import commons.Ingredient; import commons.Recipe; +import commons.RecipeIngredient; +import commons.VagueIngredient; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -14,6 +18,15 @@ import static org.junit.jupiter.api.Assertions.*; class ServerUtilsTest { static ServerUtils dv; static Recipe testRecipe; + static final List ingredients = List.of( + new Ingredient("Bread", 1, 2, 3), + new Ingredient("Cheese", 2, 2, 2), + new Ingredient("Ham", 3, 3, 3) + ); + static final List testIngredients = List.of( + new VagueIngredient(ingredients.get(0), "2 pieces of"), + new VagueIngredient(ingredients.get(1), "1 slice of") + ); final int fakeId = -1; // If suppose ID's are only positive @BeforeEach @@ -30,17 +43,28 @@ class ServerUtilsTest { Recipe r = new Recipe(); r.setName("Tosti"); - r.setIngredients(List.of("Bread", "Cheese", "Ham")); + r.setIngredients(testIngredients); r.setPreparationSteps(List.of("Step 1:", "Step 2")); testRecipe = dv.addRecipe(r); } + @AfterEach + void tearDown() throws IOException, InterruptedException { + dv.getRecipes().stream().map(Recipe::getId).forEach(id -> { + try { + dv.deleteRecipe(id); + } catch (Exception ex) { + System.err.println("Teardown failed: " + ex.getMessage()); + } + }); + } + @Test void addRecipeTest() throws IOException, InterruptedException { Recipe r = new Recipe(); r.setName("Eggs on toast"); - r.setIngredients(List.of("Bread", "egg", "salt")); + r.setIngredients(testIngredients); r.setPreparationSteps(List.of("Step 1:", "Step 2")); testRecipe = dv.addRecipe(r);