Refactored tests based on new constructor for recipes
This commit is contained in:
parent
6caf4eaa61
commit
069e60ef71
1 changed files with 43 additions and 19 deletions
|
|
@ -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<String> 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() {
|
||||
List<RecipeIngredient> 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<String> 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<RecipeIngredient> ingredients = new ArrayList<>();
|
||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("tomato"));
|
||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("potato"));
|
||||
|
||||
final long testRecipeId = 500L;
|
||||
|
||||
List<String> 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");
|
||||
|
|
@ -144,14 +157,25 @@ public class PrintExportTest {
|
|||
public void buildRecipeTextWithEmptyStepsTest() {
|
||||
List<RecipeIngredient> 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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue