diff --git a/client/src/main/java/client/utils/PrintExportService.java b/client/src/main/java/client/utils/PrintExportService.java new file mode 100644 index 0000000..17c947c --- /dev/null +++ b/client/src/main/java/client/utils/PrintExportService.java @@ -0,0 +1,67 @@ +package client.utils; + +import commons.Recipe; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class PrintExportService { + + /** + * Builds the String with all the recipe data in a human-readable format and returns said string + * @param recipe - Recipe Object that needs to be converted + * @return - String Result that is the converted recipe object + */ + public static String buildRecipeText(Recipe recipe){ + String result = "Title: " + recipe.getName() + "\nRecipe ID: " + recipe.getId() + "\n" + + "Ingredients: "; //Starts the string with name and recipe ID + for(int i =0; i ingredients = new ArrayList<>(); + ingredients.add("Banana"); + ingredients.add("Bread"); + final long testRecipeId = 1234L; + List preparationSteps = new ArrayList<>(); + preparationSteps.add("Mix Ingredients"); + preparationSteps.add("Heat in Oven"); + Recipe recipe1 = new Recipe(testRecipeId, "Banana Bread", ingredients, preparationSteps); + + assertEquals(""" + Title: Banana Bread + Recipe ID: 1234 + Ingredients: Banana, Bread,\s + Steps: + 1: Mix Ingredients + 2: Heat in Oven + """, PrintExportService.buildRecipeText(recipe1)); + + } + + @TempDir + Path tempDir; + @Test + public void validateFolderWithValidFolderTest(){ + assertDoesNotThrow(() -> PrintExportService.validateFolder(tempDir)); + } + + @Test + public void validateFolderWithNullPathTest(){ + IllegalArgumentException i = assertThrows(IllegalArgumentException.class, + ()->PrintExportService.validateFolder(null)); + assertEquals("Path is empty", i.getMessage()); + } + + @Test + public void validateFolderWithFilePathTest() throws IOException { + Path filePath = Files.createFile(tempDir.resolve("TestFile")); + IllegalArgumentException i = assertThrows(IllegalArgumentException.class, + ()->PrintExportService.validateFolder(filePath)); + assertEquals("Given path is not a folder", i.getMessage()); + } + +}