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());
|
assertEquals("Given path is not a folder", i.getMessage());
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void buildRecipeTextWithEmptyIngredientsTest(){
|
public void buildRecipeTextWithMultipleIngredientsTest() {
|
||||||
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<>();
|
List<RecipeIngredient> ingredients = new ArrayList<>();
|
||||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Flour"));
|
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Flour"));
|
||||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Sugar"));
|
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Sugar"));
|
||||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Eggs"));
|
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Eggs"));
|
||||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Butter"));
|
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Butter"));
|
||||||
|
|
||||||
final long testRecipeId = 300L;
|
final long testRecipeId = 300L;
|
||||||
|
|
||||||
List<String> steps = new ArrayList<>();
|
List<String> steps = new ArrayList<>();
|
||||||
steps.add("Mix the solid ingredients");
|
steps.add("Mix the solid ingredients");
|
||||||
steps.add("Then add the wet ingredients");
|
steps.add("Then add the wet ingredients");
|
||||||
steps.add("Bake");
|
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);
|
String result = PrintExportService.buildRecipeText(recipe);
|
||||||
|
|
||||||
assertTrue(result.contains("Some Flour"));
|
assertTrue(result.contains("Some Flour"));
|
||||||
assertTrue(result.contains("Some Sugar"));
|
assertTrue(result.contains("Some Sugar"));
|
||||||
assertTrue(result.contains("Some Eggs"));
|
assertTrue(result.contains("Some Eggs"));
|
||||||
assertTrue(result.contains("Some Butter"));
|
assertTrue(result.contains("Some Butter"));
|
||||||
assertTrue(result.contains("3: Bake"));
|
assertTrue(result.contains("3: Bake"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exportToFileWithComplexRecipeTest() throws IOException {
|
public void exportToFileWithComplexRecipeTest() throws IOException {
|
||||||
List<RecipeIngredient> ingredients = new ArrayList<>();
|
List<RecipeIngredient> ingredients = new ArrayList<>();
|
||||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("tomato"));
|
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("tomato"));
|
||||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("potato"));
|
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("potato"));
|
||||||
|
|
||||||
final long testRecipeId = 500L;
|
final long testRecipeId = 500L;
|
||||||
|
|
||||||
List<String> steps = new ArrayList<>();
|
List<String> steps = new ArrayList<>();
|
||||||
steps.add("cut up the ingredients");
|
steps.add("cut up the ingredients");
|
||||||
steps.add("Cook");
|
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 recipeData = PrintExportService.buildRecipeText(recipe);
|
||||||
String fileName = "stew_recipe.txt";
|
String fileName = "stew_recipe.txt";
|
||||||
|
|
||||||
PrintExportService.exportToFile(recipeData, tempDir, fileName);
|
PrintExportService.exportToFile(recipeData, tempDir, fileName);
|
||||||
|
|
||||||
Path expectedFile = tempDir.resolve(fileName);
|
Path expectedFile = tempDir.resolve(fileName);
|
||||||
assertTrue(Files.exists(expectedFile));
|
assertTrue(Files.exists(expectedFile));
|
||||||
|
|
||||||
String fileContent = Files.readString(expectedFile);
|
String fileContent = Files.readString(expectedFile);
|
||||||
assertTrue(fileContent.contains("stew"));
|
assertTrue(fileContent.contains("stew"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exportFileWithInvalidFolderTest(){
|
public void exportFileWithInvalidFolderTest(){
|
||||||
Path invalidfilePath = Path.of("/invalid/folder/path");
|
Path invalidfilePath = Path.of("/invalid/folder/path");
|
||||||
|
|
@ -141,17 +154,28 @@ public class PrintExportTest {
|
||||||
assertEquals(recipeData, fileContent);
|
assertEquals(recipeData, fileContent);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void buildRecipeTextWithEmptyStepsTest(){
|
public void buildRecipeTextWithEmptyStepsTest() {
|
||||||
List<RecipeIngredient> ingredients = new ArrayList<>();
|
List<RecipeIngredient> ingredients = new ArrayList<>();
|
||||||
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Water"));
|
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Water"));
|
||||||
|
|
||||||
final long testRecipeId = 200L;
|
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);
|
String result = PrintExportService.buildRecipeText(recipe);
|
||||||
|
|
||||||
assertTrue(result.contains("Title: Water"));
|
assertTrue(result.contains("Title: Water"));
|
||||||
assertTrue(result.contains("Recipe ID: 200"));
|
assertTrue(result.contains("Recipe ID: 200"));
|
||||||
assertTrue(result.contains("Ingredients: Some Water,"));
|
assertTrue(result.contains("Ingredients: Some Water"));
|
||||||
assertTrue(result.contains("Steps:"));
|
assertTrue(result.contains("Steps:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateFolderWithGarbagePathTest(){
|
public void validateFolderWithGarbagePathTest(){
|
||||||
Path garbagePath = Path.of("/this/path/does/not/exist/at/all");
|
Path garbagePath = Path.of("/this/path/does/not/exist/at/all");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue