From 7c2d302bf15dad1a81e67121112bfa72cb8ffb4e Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Tue, 6 Feb 2024 21:37:58 +0100 Subject: [PATCH] Added Test to writeToFile Method from Admin Class --- src/test/java/org/example/AdminTest.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/java/org/example/AdminTest.java b/src/test/java/org/example/AdminTest.java index 0c964fe..51def04 100644 --- a/src/test/java/org/example/AdminTest.java +++ b/src/test/java/org/example/AdminTest.java @@ -1,7 +1,12 @@ package org.example; +import org.junit.jupiter.api.Test; + import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; +import java.nio.file.Files; +import java.nio.file.Path; import static org.junit.jupiter.api.Assertions.*; @@ -22,5 +27,23 @@ class AdminTest { assertTrue(printedOutput.contains("A1001")); assertTrue(printedOutput.contains("Admin")); + } + + @Test + void writeToFile() throws IOException { + Admin admin = new Admin("Simon", "A1001", "Admin") ; + + String filename = "testAdminData.txt"; + + admin.writeToFile(admin, filename); + + String content = Files.readString(Path.of(filename)); + assertEquals("Simon\nA1001\nAdmin", content); + + Files.delete(Path.of(filename)); + + + + } } \ No newline at end of file