Skip to content
Snippets Groups Projects
Commit d21b72ab authored by Hanne-Sofie Søreide's avatar Hanne-Sofie Søreide
Browse files

Merge branch 'HS_Rewrite_fileHandling_for_recipes_and_ingredients' into 'HS_Frontend_Recipes'

Hs rewrite file handling for recipes and ingredients

See merge request !36
parents c488a0ce 1432ee61
No related branches found
No related tags found
3 merge requests!42Hs frontend recipes,!41Hs frontend recipes,!36Hs rewrite file handling for recipes and ingredients
Pipeline #215610 passed
Showing
with 511 additions and 115 deletions
......@@ -10,7 +10,6 @@ import no.ntnu.idatt1002.demo.data.recipes.*;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.ResourceBundle;
......@@ -32,10 +31,10 @@ public class RecipeController implements Initializable {
List<Recipe> suggestedRecipes = null;
IngredientsAtHand ingredientsAtHand = new IngredientsAtHand();
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.LEMON, 6, MeasuringUnit.PC));
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.MINCED_MEAT, 400, MeasuringUnit.GR));
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.POTATO, 4, MeasuringUnit.PC));
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.MILK, 8, MeasuringUnit.DL));
ingredientsAtHand.addIngredient(FoodItem.LEMON);
ingredientsAtHand.addIngredient(FoodItem.MINCED_MEAT);
ingredientsAtHand.addIngredient(FoodItem.POTATO);
ingredientsAtHand.addIngredient(FoodItem.MILK);
......
package no.ntnu.idatt1002.demo.data.recipes;
import java.io.*;
import java.util.List;
import java.util.Scanner;
//TODO: Refactor to make use of generics, which requires
// refactoring of more classes and write mor eunit tests and JavaDoc.
public class FileHandler {
private static final String fileType = ".register";
private static final String registerName = "RecipeRegister";
private static final String filePath = "src/main/resources/recipes/";
public static void writeRegister(RecipeRegister recipeRegister, String title) {
if (recipeRegister == null) {
throw new IllegalArgumentException("Only a valid register object can be written to file.");
}
try (FileWriter fileWriter = new FileWriter(filePath + title + fileType);) {
recipeRegister.getRecipes().forEach((recipe) ->
{
try {
fileWriter.write(formatRecipe(recipe).toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
);
} catch (IOException e) {
e.printStackTrace();
}
}
public static StringBuilder formatRecipe(Recipe recipe) {
StringBuilder sb = new StringBuilder();
sb.append("# ")
.append(recipe.getName())
.append("\n")
.append(formatIngredientList(recipe.getIngredientList()))
.append("\n")
.append(recipe.getInstructions())
.append("\n\n");
return sb;
}
public static StringBuilder formatIngredientList(List<RecipeIngredient> ingredientList) {
StringBuilder sb = new StringBuilder();
ingredientList.forEach((ingredient) -> {
sb.append("- ")
.append(ingredient.getFoodType())
.append(" | ")
.append(ingredient.getAmount())
.append(" | ")
.append(ingredient.getUnit())
.append("\n");
});
return sb;
}
//TODO: Midlertidig for testing.
public static void readToTerminal(String title) throws FileNotFoundException {
File file = new File(filePath + title + fileType);
Scanner sc = new Scanner(file);
while (sc.hasNext()) {
System.out.println(sc.nextLine());
}
}
public static RecipeRegister readRecipeRegister(String title) throws FileNotFoundException {
File file = new File(filePath + title + fileType);
RecipeRegister register = new RecipeRegister();
try (Scanner sc = new Scanner(file)) {
sc.useDelimiter("#");
String line;
while (sc.hasNext()) {
line = sc.next();
if (!line.isBlank()) {
register.addRecipe(readRecipe(line));
}
}
} catch (FileNotFoundException e) {
System.out.println("The file was not found.");
return null;
}
return register;
}
public static Recipe readRecipe(String readRecipe) {
Scanner sc = new Scanner(readRecipe);
Recipe recipe;
String instructions = "None";
String recipeName = sc.nextLine().strip();
StringBuilder sb = new StringBuilder();
String line;
recipe = new Recipe(recipeName, instructions);
while (sc.hasNextLine()) {
line = sc.nextLine();
if (line.startsWith("-")) {
String[] ingredientParts = line.split("\\|");
FoodItem ingredientType = FoodItem.valueOf(ingredientParts[0].replaceFirst("-", "").strip());
double ingredientAmount = Double.parseDouble(ingredientParts[1].strip());
MeasuringUnit ingredientUnit = MeasuringUnit.valueOf(ingredientParts[2].strip());
recipe.addIngredient(ingredientType, ingredientAmount, ingredientUnit);
} else {
if (!line.isBlank()) {
sb.append(line).append("\n");
}
}
}
recipe.setInstructions(String.valueOf(sb));
return recipe;
}
// ================ Ingredients at hand ===============================
public static void writeIngredientsAtHand(IngredientsAtHand ingredientsAtHand, String title) throws IOException {
if (ingredientsAtHand == null) {
throw new IllegalArgumentException("Only a valid register object can be written to file.");
}
StringBuilder sb = new StringBuilder();
try (FileWriter fileWriter = new FileWriter(filePath + title + fileType);) {
ingredientsAtHand.getIngredientsAtHand().forEach((ingredient) -> {
sb.append(ingredient).append("\n");
});
try {
fileWriter.write(String.valueOf(sb));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public static IngredientsAtHand readIngredientsAtHand(String title) {
File file = new File(filePath + title + fileType);
IngredientsAtHand ingredientsAtHand = new IngredientsAtHand();
try (Scanner sc = new Scanner(file)) {
String line;
while (sc.hasNext()) {
line = sc.next();
if (!line.isBlank()) {
ingredientsAtHand.addIngredient(FoodItem.valueOf(line));
}
}
} catch (FileNotFoundException e) {
System.out.println("The file was not found.");
return null;
}
return ingredientsAtHand;
}
}
\ No newline at end of file
......@@ -3,22 +3,16 @@ package no.ntnu.idatt1002.demo.data.recipes;
import java.util.ArrayList;
import java.util.List;
/**
* The IngredientsAtHand class contains a collection of Ingredient objects that are currently available to the user.
* Only one instance of each ingredient type may exist in the collection. If an ingredient is already present in the
* collection, the old will be replaced by the new.
*
* @author hannesofie
*/
public class IngredientsAtHand {
//TODO: go through JavaDoc after refactoring.
private final List<Ingredient> ingredientsAtHand = new ArrayList<>();
private final ArrayList<FoodItem> ingredientsAtHand = new ArrayList<>();
/**
* The method returns the collection of ingredients at hand as an arraylist of ingredient objects.
* @return The collection of ingredients at hand to the user.
*/
public List<Ingredient> getIngredientsAtHand() {
public List<FoodItem> getIngredientsAtHand() {
return ingredientsAtHand;
}
......@@ -26,49 +20,15 @@ public class IngredientsAtHand {
* The method takes in an ingredient object and adds it to the collection of ingredients at hand.
* @param ingredient The ingredient object to add to the collection of ingredients at hand.
*/
public void addIngredient(Ingredient ingredient) {
public void addIngredient(FoodItem ingredient) {
this.ingredientsAtHand.add(ingredient);
}
/**
* Returns null if no ingredient of the requested type is found in the collection.
* @param ingredientType What type of food the ingredient is.
* @return The ingredient of the specified type found among the ingredients at hand, null otherwise.
*/
public Ingredient getIngredient(FoodItem ingredientType) {
if(ingredientType == null) return null;
return this.getIngredientsAtHand().stream()
.filter((ingredient) -> ingredient.getFoodType() == ingredientType)
.findFirst().orElse(null);
//TODO: Unit tests and javadoc
public boolean atHand(FoodItem foodItem) {
return ingredientsAtHand.stream().anyMatch( (in) -> in.equals(foodItem));
}
/**
* The method takes in three parameters. The method first checks if the Ingredient is at hand in the first place.
* If it is, the old amount and unit of this ingredient are replaced by the provided amount and unit if they
* differ. If not, the ingredient is left as is. If the ingredient is not in the collection,
* @param ingredientType What type of food the ingredient is.
* @param amount The amount of the ingredient.
* @return True if Ingredient is successfully altered or added, false if not.
*/
public boolean alterIngredient(FoodItem ingredientType, double amount, MeasuringUnit unit) {
//TODO: Consider handling exceptions differently.
if(ingredientsAtHand.stream().anyMatch((ingredient) -> ingredient.getFoodType() == ingredientType)) {
try {
getIngredient(ingredientType).setAmount(amount);
getIngredient(ingredientType).setUnit(unit);
} catch (IllegalArgumentException e) {
return false;
}
} else {
try {
addIngredient(new Ingredient(ingredientType, amount, unit));
} catch (IllegalArgumentException e) {
return false;
}
}
return true;
}
/**
* The method takes in a value of the FoodItem enum as a parameter and removes it from the collection of
......@@ -78,7 +38,8 @@ public class IngredientsAtHand {
* @return True if the ingredient was found among the ingredients at hand and removed, false otherwise.
*/
public boolean removeIngredient(FoodItem ingredientType) {
return ingredientsAtHand.removeIf((ingredient) -> ingredient.getFoodType() == ingredientType);
return ingredientsAtHand.remove(ingredientType);
}
}
package no.ntnu.idatt1002.demo.data.recipes;
import java.util.ArrayList;
import java.util.List;
/**
* The IngredientsAtHandDetailed class contains a collection of Ingredient objects that are currently available to the user.
* Only one instance of each ingredient type may exist in the collection. If an ingredient is already present in the
* collection, the old will be replaced by the new.
*
* @author hannesofie
*/
public class IngredientsAtHandDetailed {
private final List<Ingredient> ingredientsAtHand = new ArrayList<>();
/**
* The method returns the collection of ingredients at hand as an arraylist of ingredient objects.
* @return The collection of ingredients at hand to the user.
*/
public List<Ingredient> getIngredientsAtHand() {
return ingredientsAtHand;
}
/**
* The method takes in an ingredient object and adds it to the collection of ingredients at hand.
* @param ingredient The ingredient object to add to the collection of ingredients at hand.
*/
public void addIngredient(Ingredient ingredient) {
this.ingredientsAtHand.add(ingredient);
}
/**
* Returns null if no ingredient of the requested type is found in the collection.
* @param ingredientType What type of food the ingredient is.
* @return The ingredient of the specified type found among the ingredients at hand, null otherwise.
*/
public Ingredient getIngredient(FoodItem ingredientType) {
if(ingredientType == null) return null;
return this.getIngredientsAtHand().stream()
.filter((ingredient) -> ingredient.getFoodType() == ingredientType)
.findFirst().orElse(null);
}
/**
* The method takes in three parameters. The method first checks if the Ingredient is at hand in the first place.
* If it is, the old amount and unit of this ingredient are replaced by the provided amount and unit if they
* differ. If not, the ingredient is left as is. If the ingredient is not in the collection,
* @param ingredientType What type of food the ingredient is.
* @param amount The amount of the ingredient.
* @return True if Ingredient is successfully altered or added, false if not.
*/
public boolean alterIngredient(FoodItem ingredientType, double amount, MeasuringUnit unit) {
//TODO: Consider handling exceptions differently.
if(ingredientsAtHand.stream().anyMatch((ingredient) -> ingredient.getFoodType() == ingredientType)) {
try {
getIngredient(ingredientType).setAmount(amount);
getIngredient(ingredientType).setUnit(unit);
} catch (IllegalArgumentException e) {
return false;
}
} else {
try {
addIngredient(new Ingredient(ingredientType, amount, unit));
} catch (IllegalArgumentException e) {
return false;
}
}
return true;
}
/**
* The method takes in a value of the FoodItem enum as a parameter and removes it from the collection of
* ingredients at hand if it exists and returns true. If no ingredient of the given type was found in the
* collection, false is returned.
* @param ingredientType What type of food the ingredient is.
* @return True if the ingredient was found among the ingredients at hand and removed, false otherwise.
*/
public boolean removeIngredient(FoodItem ingredientType) {
return ingredientsAtHand.removeIf((ingredient) -> ingredient.getFoodType() == ingredientType);
}
}
......@@ -96,19 +96,35 @@ public class Recipe {
throw new IllegalArgumentException("The collection of ingredients at hand is empty.");
} else {
missingIngredients = 0;
int notMissing = (int) ingredientList.stream().filter((inRecipe) -> ingredientsAtHand.atHand(inRecipe.getFoodType())).count();
ingredientList.forEach((inRecipe) -> {
inRecipe.setAtHand(ingredientsAtHand.atHand(inRecipe.getFoodType()));
});
};
/* ingredientList.forEach((inRecipe) -> {
ingredientsAtHand.getIngredientsAtHand().forEach((atHand) -> {
if(inRecipe.getFoodType() == atHand.getFoodType()) {
System.out.println("----");
System.out.println(inRecipe.getFoodType());
System.out.println(atHand);
System.out.println("----");
if(inRecipe.getFoodType() == atHand) {
inRecipe.setAtHand(true);
} else {
inRecipe.setAtHand(false);
missingIngredients += 1;
}
});
});
}
});*/
}
public int getMissingIngredients() {
return missingIngredients;
}
......
......@@ -4,7 +4,7 @@ package no.ntnu.idatt1002.demo.data.recipes;
* The RecipeIngredient class is an extension of the Ingredient class used as part of recipes
* that also stored the boolean value 'atHand'. This value can be set to true whenever the given ingredient,
* being part of a recipe, is also at hand to the user. Ingredients that the user has available are stored in
* the IngredientsAtHand class.
* the IngredientsAtHandDetailed class.
*
* @author hannesofie
*/
......
......@@ -28,4 +28,5 @@ public class RecipeRegister {
filter((recipe) -> recipe.getName().equals(name))
.findFirst().orElse(null);
}
}
# Meat, cheese and potatoes
- MINCED_MEAT | 500.0 | GR
- POTATO | 750.0 | GR
- YELLOW_CHEESE | 2.0 | DL
Instructions must be written continuously in one line. No line shifts.
Testing another line of instructions!
# Meat, cheese and lemons
- MINCED_MEAT | 500.0 | GR
- LEMON | 750.0 | GR
- YELLOW_CHEESE | 2.0 | DL
Instructions
# Another recipe added for testing
- ONION | 5.0 | PC
- LEMON | 750.0 | GR
- POTATO | 10.0 | PC
Instructions for another dish.
\ No newline at end of file
package no.ntnu.idatt1002.demo.data.recipes;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
class FileHandlerTest {
RecipeRegister recipeRegister = new RecipeRegister();
IngredientsAtHand ingredientsAtHand = new IngredientsAtHand();
Recipe recipe1;
Recipe recipe2;
@BeforeEach
void beforeEach() {
recipe1 = new Recipe("Meat, cheese and potatoes", "Instructions");
recipe1.addIngredient(FoodItem.MINCED_MEAT, 500, MeasuringUnit.GR);
recipe1.addIngredient(FoodItem.POTATO, 750, MeasuringUnit.GR);
recipe1.addIngredient(FoodItem.YELLOW_CHEESE, 2, MeasuringUnit.DL);
recipe2 = new Recipe("Meat, cheese and lemons", "Instructions");
recipe2.addIngredient(FoodItem.MINCED_MEAT, 500, MeasuringUnit.GR);
recipe2.addIngredient(FoodItem.LEMON, 750, MeasuringUnit.GR);
recipe2.addIngredient(FoodItem.YELLOW_CHEESE, 2, MeasuringUnit.DL);
recipeRegister.addRecipe(recipe1);
recipeRegister.addRecipe(recipe2);
// For AtHand:
ingredientsAtHand.addIngredient(FoodItem.POTATO);
ingredientsAtHand.addIngredient(FoodItem.MILK);
ingredientsAtHand.addIngredient(FoodItem.LEMON);
ingredientsAtHand.addIngredient(FoodItem.MINCED_MEAT);
}
@Test
@DisplayName("Write recipe register correctly to file as text.")
void writeRecipeRegisterToFile() throws FileNotFoundException {
assertAll(() -> FileHandler.writeRegister(recipeRegister, "RecipeRegister"));
FileHandler.readToTerminal("RecipeRegister");
}
@Test
@DisplayName("Read recipe register correctly from file to object.")
void readRecipeRegisterFromFile() throws FileNotFoundException {
// Read test register into a register object.
// Write the object and print to terminal.
assertAll(() -> FileHandler.readRecipeRegister("testReadRegisterFromFile"));
RecipeRegister registerReadFromTestFile = FileHandler.readRecipeRegister("testReadRegisterFromFile");
// Write the register object to file and read to terminal:
FileHandler.writeRegister(registerReadFromTestFile, "ReadAndWrittenRegister");
FileHandler.readToTerminal("ReadAndWrittenRegister");
// Another iteration to spot accumulating spaces or new lines.
RecipeRegister secondRegister = FileHandler.readRecipeRegister("ReadAndWrittenRegister");
FileHandler.writeRegister(secondRegister, "secondGeneration");
}
// Ingredients at hand nesting
@Test
@DisplayName("Write ingredients at hand to file.")
void writeIngredientsAtHandToFile() throws FileNotFoundException {
assertAll(() -> FileHandler.writeIngredientsAtHand(ingredientsAtHand, "AtHandRegister"));
FileHandler.readToTerminal("AtHandRegister");
}
}
\ No newline at end of file
package no.ntnu.idatt1002.demo.data.recipes;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class IngredientsAtHandDetailedTest {
IngredientsAtHandDetailed ingredientsAtHand = new IngredientsAtHandDetailed();
@BeforeEach
void beforeEach() {
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.LEMON, 3, MeasuringUnit.PC));
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.MILK, 1.5f, MeasuringUnit.L));
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.MINCED_MEAT, 400, MeasuringUnit.GR));
}
@Test
@DisplayName("The getIngredient method returns the correct ingredient.")
void getIngredientReturnsSuccessfully() {
assertEquals(new Ingredient(FoodItem.LEMON, 3, MeasuringUnit.PC),
ingredientsAtHand.getIngredient(FoodItem.LEMON));
}
@Test
@DisplayName("The getIngredient method returns null if the ingredient is not in the collection.")
void getIngredientReturnsNullWhenNotFoundOrNull(){
assertNull(ingredientsAtHand.getIngredient(FoodItem.ONION));
assertNull(ingredientsAtHand.getIngredient(null));
}
@Test
@DisplayName("Altering ingredient successfully and return true.")
void alterIngredientSuccessfully() {
assertNotEquals(new Ingredient(FoodItem.ONION, 500, MeasuringUnit.GR),
ingredientsAtHand.getIngredient(FoodItem.ONION));
assertTrue(ingredientsAtHand.alterIngredient(FoodItem.ONION, 500, MeasuringUnit.GR));
assertEquals(new Ingredient(FoodItem.ONION, 500, MeasuringUnit.GR),
ingredientsAtHand.getIngredient(FoodItem.ONION));
}
@Test
@DisplayName("Altering ingredient that does not yet exist in collection adds it and returns true.")
void alterNewIngredientAddsIt() {
int ingredientsAtStart = ingredientsAtHand.getIngredientsAtHand().size();
assertTrue(ingredientsAtHand.alterIngredient(FoodItem.ORANGE, 8, MeasuringUnit.PC));
assertEquals(ingredientsAtStart + 1, ingredientsAtHand.getIngredientsAtHand().size());
}
@Test
@DisplayName("Attempting to alter ingredient in illegal way does not alter the collection and returns false.")
void alterIngredientUnchangedForInvalidChange() {
assertFalse(ingredientsAtHand.alterIngredient(null, 350, MeasuringUnit.GR));
assertEquals(new Ingredient(FoodItem.LEMON, 3, MeasuringUnit.PC),
ingredientsAtHand.getIngredient(FoodItem.LEMON));
}
@Test
@DisplayName("Altering an ingredients without changing values, leaves no change on the collection and returns true.")
void alterNothingLeavesCollectionIntact() {
int ingredientsAtStart = ingredientsAtHand.getIngredientsAtHand().size();
assertTrue(ingredientsAtHand.alterIngredient(FoodItem.LEMON, 3, MeasuringUnit.PC));
assertEquals(ingredientsAtStart, ingredientsAtHand.getIngredientsAtHand().size());
}
@Test
@DisplayName("Ingredient is removed successfully and true is returned.")
void removeIngredientSuccessfully() {
int ingredientsAtStart = ingredientsAtHand.getIngredientsAtHand().size();
assertTrue(ingredientsAtHand.removeIngredient(FoodItem.LEMON));
assertEquals(ingredientsAtStart-1, ingredientsAtHand.getIngredientsAtHand().size());
}
@Test
@DisplayName("Removing ingredient that is not in the collection, leaves it unchanged and returns false.")
void removeIngredientNotInCollection() {
assertFalse(ingredientsAtHand.removeIngredient(FoodItem.SALSA_SAUCE));
}
}
\ No newline at end of file
......@@ -12,66 +12,17 @@ class IngredientsAtHandTest {
@BeforeEach
void beforeEach() {
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.LEMON, 3, MeasuringUnit.PC));
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.MILK, 1.5f, MeasuringUnit.L));
ingredientsAtHand.addIngredient(new Ingredient(FoodItem.MINCED_MEAT, 400, MeasuringUnit.GR));
ingredientsAtHand.addIngredient(FoodItem.LEMON);
ingredientsAtHand.addIngredient(FoodItem.MILK);
ingredientsAtHand.addIngredient(FoodItem.MINCED_MEAT);
}
@Test
@DisplayName("The getIngredient method returns the correct ingredient.")
void getIngredientReturnsSuccessfully() {
assertEquals(new Ingredient(FoodItem.LEMON, 3, MeasuringUnit.PC),
ingredientsAtHand.getIngredient(FoodItem.LEMON));
}
@Test
@DisplayName("The getIngredient method returns null if the ingredient is not in the collection.")
void getIngredientReturnsNullWhenNotFoundOrNull(){
assertNull(ingredientsAtHand.getIngredient(FoodItem.ONION));
assertNull(ingredientsAtHand.getIngredient(null));
}
@Test
@DisplayName("Altering ingredient successfully and return true.")
void alterIngredientSuccessfully() {
assertNotEquals(new Ingredient(FoodItem.ONION, 500, MeasuringUnit.GR),
ingredientsAtHand.getIngredient(FoodItem.ONION));
assertTrue(ingredientsAtHand.alterIngredient(FoodItem.ONION, 500, MeasuringUnit.GR));
assertEquals(new Ingredient(FoodItem.ONION, 500, MeasuringUnit.GR),
ingredientsAtHand.getIngredient(FoodItem.ONION));
}
@Test
@DisplayName("Altering ingredient that does not yet exist in collection adds it and returns true.")
void alterNewIngredientAddsIt() {
int ingredientsAtStart = ingredientsAtHand.getIngredientsAtHand().size();
assertTrue(ingredientsAtHand.alterIngredient(FoodItem.ORANGE, 8, MeasuringUnit.PC));
assertEquals(ingredientsAtStart + 1, ingredientsAtHand.getIngredientsAtHand().size());
}
@Test
@DisplayName("Attempting to alter ingredient in illegal way does not alter the collection and returns false.")
void alterIngredientUnchangedForInvalidChange() {
assertFalse(ingredientsAtHand.alterIngredient(null, 350, MeasuringUnit.GR));
assertEquals(new Ingredient(FoodItem.LEMON, 3, MeasuringUnit.PC),
ingredientsAtHand.getIngredient(FoodItem.LEMON));
}
@Test
@DisplayName("Altering an ingredients without changing values, leaves no change on the collection and returns true.")
void alterNothingLeavesCollectionIntact() {
int ingredientsAtStart = ingredientsAtHand.getIngredientsAtHand().size();
assertTrue(ingredientsAtHand.alterIngredient(FoodItem.LEMON, 3, MeasuringUnit.PC));
assertEquals(ingredientsAtStart, ingredientsAtHand.getIngredientsAtHand().size());
@DisplayName("The atHand method returns true/false correctly.")
void atHandReturnsSuccessfully() {
assertTrue(ingredientsAtHand.atHand(FoodItem.LEMON));
assertFalse(ingredientsAtHand.atHand(FoodItem.YELLOW_CHEESE));
}
@Test
......
......@@ -93,8 +93,8 @@ class RecipeTest {
@DisplayName("Updating ingredient status works as expected.")
void updateIngredientStatus() {
IngredientsAtHand inFridge = new IngredientsAtHand();
inFridge.addIngredient(new Ingredient(FoodItem.MINCED_MEAT, 400, MeasuringUnit.GR));
inFridge.addIngredient(new Ingredient(FoodItem.YELLOW_CHEESE, 500, MeasuringUnit.GR));
inFridge.addIngredient(FoodItem.MINCED_MEAT);
inFridge.addIngredient(FoodItem.YELLOW_CHEESE);
recipe.getIngredientList().forEach((ingredient) -> assertFalse(ingredient.isAtHand()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment