From 069e60ef7101d01989354e26327350809f19e3ef Mon Sep 17 00:00:00 2001 From: Rithvik Sriram Date: Wed, 14 Jan 2026 23:12:03 +0100 Subject: [PATCH] Refactored tests based on new constructor for recipes --- .../java/client/scenes/PrintExportTest.java | 62 +++++++++++++------ 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/client/src/test/java/client/scenes/PrintExportTest.java b/client/src/test/java/client/scenes/PrintExportTest.java index 00a85ae..69a293f 100644 --- a/client/src/test/java/client/scenes/PrintExportTest.java +++ b/client/src/test/java/client/scenes/PrintExportTest.java @@ -62,56 +62,69 @@ public class PrintExportTest { assertEquals("Given path is not a folder", i.getMessage()); } @Test - public void buildRecipeTextWithEmptyIngredientsTest(){ - final long testRecipeId = 100L; - List preparationSteps = new ArrayList<>(); - preparationSteps.add("Just wait"); - Recipe recipe = new Recipe(testRecipeId, "Empty Recipe", new ArrayList<>(), preparationSteps); - String result = PrintExportService.buildRecipeText(recipe); - assertTrue(result.contains("Title: Empty Recipe")); - assertTrue(result.contains("Recipe ID: 100")); - assertTrue(result.contains("Ingredients: ")); - assertTrue(result.contains("1: Just wait")); - } - @Test - public void buildRecipeTextWithMultipleIngredientsTest(){ + public void buildRecipeTextWithMultipleIngredientsTest() { List ingredients = new ArrayList<>(); ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Flour")); ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Sugar")); ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Eggs")); ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Butter")); + final long testRecipeId = 300L; + List steps = new ArrayList<>(); steps.add("Mix the solid ingredients"); steps.add("Then add the wet ingredients"); steps.add("Bake"); - Recipe recipe = new Recipe(testRecipeId, "Cake", ingredients, steps); + + Recipe recipe = new Recipe( + testRecipeId, + "Cake", + "Test description", + ingredients, + steps + ); + String result = PrintExportService.buildRecipeText(recipe); + assertTrue(result.contains("Some Flour")); assertTrue(result.contains("Some Sugar")); assertTrue(result.contains("Some Eggs")); assertTrue(result.contains("Some Butter")); assertTrue(result.contains("3: Bake")); } + @Test public void exportToFileWithComplexRecipeTest() throws IOException { List ingredients = new ArrayList<>(); ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("tomato")); ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("potato")); + final long testRecipeId = 500L; + List steps = new ArrayList<>(); steps.add("cut up the ingredients"); steps.add("Cook"); - Recipe recipe = new Recipe(testRecipeId, "stew", ingredients, steps); + + Recipe recipe = new Recipe( + testRecipeId, + "stew", + "Test description", + ingredients, + steps + ); + String recipeData = PrintExportService.buildRecipeText(recipe); String fileName = "stew_recipe.txt"; + PrintExportService.exportToFile(recipeData, tempDir, fileName); + Path expectedFile = tempDir.resolve(fileName); assertTrue(Files.exists(expectedFile)); + String fileContent = Files.readString(expectedFile); assertTrue(fileContent.contains("stew")); - } + @Test public void exportFileWithInvalidFolderTest(){ Path invalidfilePath = Path.of("/invalid/folder/path"); @@ -141,17 +154,28 @@ public class PrintExportTest { assertEquals(recipeData, fileContent); } @Test - public void buildRecipeTextWithEmptyStepsTest(){ + public void buildRecipeTextWithEmptyStepsTest() { List ingredients = new ArrayList<>(); ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Water")); + final long testRecipeId = 200L; - Recipe recipe = new Recipe(testRecipeId, "Water", ingredients, new ArrayList<>()); + + Recipe recipe = new Recipe( + testRecipeId, + "Water", + "Test description", + ingredients, + new ArrayList<>() + ); + String result = PrintExportService.buildRecipeText(recipe); + assertTrue(result.contains("Title: Water")); assertTrue(result.contains("Recipe ID: 200")); - assertTrue(result.contains("Ingredients: Some Water,")); + assertTrue(result.contains("Ingredients: Some Water")); assertTrue(result.contains("Steps:")); } + @Test public void validateFolderWithGarbagePathTest(){ Path garbagePath = Path.of("/this/path/does/not/exist/at/all");