From a3616d8d675472fd59b3287beadfc5fbbb82253a Mon Sep 17 00:00:00 2001 From: Sverre Halvorsen <sverrgha@stud.ntnu.no> Date: Mon, 26 Feb 2024 10:26:05 +0100 Subject: [PATCH 1/3] Feat: Initialize Recipie class. --- .../stud/ntnu/idatt1005/model/Recipe.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/stud/ntnu/idatt1005/model/Recipe.java diff --git a/src/main/java/stud/ntnu/idatt1005/model/Recipe.java b/src/main/java/stud/ntnu/idatt1005/model/Recipe.java new file mode 100644 index 0000000..d3cfbd9 --- /dev/null +++ b/src/main/java/stud/ntnu/idatt1005/model/Recipe.java @@ -0,0 +1,57 @@ +package stud.ntnu.idatt1005.model; + +import stud.ntnu.idatt1005.register.GroceryRegister; +import stud.ntnu.idatt1005.register.Steps; + +/** + * This is an entity class representing a recipe + * It contains the name, groceries and steps of the recipe + * Goal: act as a model for a recipe + */ +public class Recipe { + + // The name of the recipe + private final String name; + + // The groceries needed for the recipe + private GroceryRegister recipeGroceries; + + // The steps needed to make the recipe + private Steps steps; + +/** + * Constructor for the Recipe class + * @param name the name of the recipe + * @param recipeGroceries the groceries needed for the recipe + * @param steps the steps needed to make the recipe + */ + public Recipe(String name, GroceryRegister recipeGroceries, Steps steps) { + this.name = name; + this.recipeGroceries = recipeGroceries; + this.steps = steps; + } + + /** + * Get the name of the recipe + * @return the name of the recipe + */ + public String getName() { + return name; + } + + /** + * Get the groceries needed for the recipe + * @return the groceries needed for the recipe + */ + public GroceryRegister getRecipeGroceries() { + return recipeGroceries; + } + + /** + * Get the steps needed to make the recipe + * @return the steps needed to make the recipe + */ + public Steps getSteps() { + return steps; + } +} -- GitLab From 743abbfede502d83ac8e3ba968726dda90e17dbb Mon Sep 17 00:00:00 2001 From: Sverre Halvorsen <sverrgha@stud.ntnu.no> Date: Mon, 26 Feb 2024 11:08:23 +0100 Subject: [PATCH 2/3] Feat: Implement test class RecipeTest for Recipe class --- .../stud/ntnu/idatt1005/model/RecipeTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/test/java/stud/ntnu/idatt1005/model/RecipeTest.java diff --git a/src/test/java/stud/ntnu/idatt1005/model/RecipeTest.java b/src/test/java/stud/ntnu/idatt1005/model/RecipeTest.java new file mode 100644 index 0000000..e3366d4 --- /dev/null +++ b/src/test/java/stud/ntnu/idatt1005/model/RecipeTest.java @@ -0,0 +1,60 @@ +package stud.ntnu.idatt1005.model; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import stud.ntnu.idatt1005.register.GroceryRegister; +import stud.ntnu.idatt1005.register.Steps; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class RecipeTest { + + static Recipe recipe; + static GroceryRegister groceries; + static Steps steps; + + + @BeforeAll + static void setUp() { + Grocery apple = new Grocery("apple", 1, "fruit", null); + Grocery banana = new Grocery("banana", 2, "fruit", null); + groceries = new GroceryRegister(); + groceries.addGrocery(apple); + groceries.addGrocery(banana); + + steps = new Steps(); + steps.addStep("Step 1"); + steps.addStep("Step 2"); + + recipe = new Recipe("Apple Banana Smoothie", groceries, steps); + + } + + @Test + @DisplayName("Test getName()") + void testGetName() { + assertEquals("Apple Banana Smoothie", recipe.getName()); + } + + @Test + @DisplayName("Test getRecipeGroceries()") + void testGetRecipeGroceries() { + assertEquals(2, recipe.getRecipeGroceries().getRegister().size()); + assertEquals(groceries.getGrocery("apple"), + recipe.getRecipeGroceries().getRegister().get("apple")); + assertEquals(groceries.getGrocery("banana"), + recipe.getRecipeGroceries().getRegister().get("banana")); + } + + @Test + void testGetSteps() { + List<String> expected = new ArrayList<>(); + expected.add("Step 1"); + expected.add("Step 2"); + assertEquals(expected, recipe.getRecipeSteps()); + } +} \ No newline at end of file -- GitLab From 48ce470d6ab7874e4f06e44da3216ef134e2c1b5 Mon Sep 17 00:00:00 2001 From: Sverre Halvorsen <sverrgha@stud.ntnu.no> Date: Mon, 26 Feb 2024 11:17:44 +0100 Subject: [PATCH 3/3] Style: Format class to align with checkstyle --- .../stud/ntnu/idatt1005/model/Recipe.java | 54 +++++++++++-------- .../stud/ntnu/idatt1005/model/RecipeTest.java | 1 + 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/main/java/stud/ntnu/idatt1005/model/Recipe.java b/src/main/java/stud/ntnu/idatt1005/model/Recipe.java index d3cfbd9..7e97fe1 100644 --- a/src/main/java/stud/ntnu/idatt1005/model/Recipe.java +++ b/src/main/java/stud/ntnu/idatt1005/model/Recipe.java @@ -1,29 +1,38 @@ package stud.ntnu.idatt1005.model; +import java.util.List; import stud.ntnu.idatt1005.register.GroceryRegister; import stud.ntnu.idatt1005.register.Steps; + /** - * This is an entity class representing a recipe - * It contains the name, groceries and steps of the recipe - * Goal: act as a model for a recipe + * This is an entity class representing a recipe. + * It contains the name, groceries and steps of the recipe. + * Goal: act as a model for a recipe. */ public class Recipe { - // The name of the recipe + /** + * The name of the recipe. + */ private final String name; - // The groceries needed for the recipe - private GroceryRegister recipeGroceries; + /** + * The groceries needed for the recipe. + */ + private final GroceryRegister recipeGroceries; - // The steps needed to make the recipe - private Steps steps; + /** + * The steps needed to make the recipe. + */ + private final Steps steps; -/** - * Constructor for the Recipe class - * @param name the name of the recipe - * @param recipeGroceries the groceries needed for the recipe - * @param steps the steps needed to make the recipe + /** + * Constructor for the Recipe class. + * + * @param name the name of the recipe. + * @param recipeGroceries the groceries needed for the recipe. + * @param steps the steps needed to make the recipe. */ public Recipe(String name, GroceryRegister recipeGroceries, Steps steps) { this.name = name; @@ -32,26 +41,29 @@ public class Recipe { } /** - * Get the name of the recipe - * @return the name of the recipe + * Get the name of the recipe. + * + * @return the name of the recipe. */ public String getName() { return name; } /** - * Get the groceries needed for the recipe - * @return the groceries needed for the recipe + * Get the groceries needed for the recipe. + * + * @return the groceries needed for the recipe. */ public GroceryRegister getRecipeGroceries() { return recipeGroceries; } /** - * Get the steps needed to make the recipe - * @return the steps needed to make the recipe + * Get the steps needed to make the recipe. + * + * @return the steps needed to make the recipe. */ - public Steps getSteps() { - return steps; + public List<String> getRecipeSteps() { + return steps.getSteps(); } } diff --git a/src/test/java/stud/ntnu/idatt1005/model/RecipeTest.java b/src/test/java/stud/ntnu/idatt1005/model/RecipeTest.java index e3366d4..be722b0 100644 --- a/src/test/java/stud/ntnu/idatt1005/model/RecipeTest.java +++ b/src/test/java/stud/ntnu/idatt1005/model/RecipeTest.java @@ -51,6 +51,7 @@ class RecipeTest { } @Test + @DisplayName("Test getRecipeSteps()") void testGetSteps() { List<String> expected = new ArrayList<>(); expected.add("Step 1"); -- GitLab