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