added test to improve coverage

This commit is contained in:
Mei Chang van der Werff 2026-01-10 19:50:31 +01:00
commit 78fdb64bdf

View file

@ -17,13 +17,15 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class PrintExportTest {
@TempDir
Path tempDir;
@Test
public void buildRecipeTextTest(){
List<RecipeIngredient> ingredients = new ArrayList<>();
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Banana"));
ingredients.add(DefaultValueFactory.getDefaultVagueIngredient("Bread"));
final long testRecipeId = 1234L;
List<String> preparationSteps = new ArrayList<>();
preparationSteps.add("Mix Ingredients");
@ -38,11 +40,8 @@ public class PrintExportTest {
1: Mix Ingredients
2: Heat in Oven
""", PrintExportService.buildRecipeText(recipe1));
}
@TempDir
Path tempDir;
@Test
public void validateFolderWithValidFolderTest(){
assertDoesNotThrow(() -> PrintExportService.validateFolder(tempDir));
@ -63,4 +62,27 @@ public class PrintExportTest {
assertEquals("Given path is not a folder", i.getMessage());
}
@Test
public void succesExportTest() throws IOException {
String data = "recipe data";
String fileName = "succes.txt";
Path filePath = tempDir.resolve(fileName);
PrintExportService.exportToFile(data,tempDir,fileName);
assertTrue(Files.exists(filePath));
assertEquals(data, Files.readString(filePath));
}
@Test
public void failExportTest(){
String data = "recipe data";
String fileName = "succes.txt";
Path filePath = tempDir.resolve("fail/failDir");
IllegalArgumentException i = assertThrows(IllegalArgumentException.class,
()->PrintExportService.exportToFile(data,filePath,fileName));
assertEquals("Folder does not exist", i.getMessage());
}
}