From 80af156e68c4cb71d83d56c4f4df76ce2769a333 Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Tue, 6 Feb 2024 21:54:23 +0100 Subject: [PATCH] Added Test to readFromFile Method from Admin Class --- src/test/java/org/example/AdminTest.java | 26 +++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/example/AdminTest.java b/src/test/java/org/example/AdminTest.java index 51def04..f844ece 100644 --- a/src/test/java/org/example/AdminTest.java +++ b/src/test/java/org/example/AdminTest.java @@ -2,11 +2,10 @@ package org.example; import org.junit.jupiter.api.Test; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; +import java.io.*; import java.nio.file.Files; import java.nio.file.Path; +import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -42,8 +41,29 @@ class AdminTest { Files.delete(Path.of(filename)); + } + + @Test + void readFromFile() throws IOException { + + try (PrintWriter writer = new PrintWriter(new FileWriter("testAdminData.txt"))){ + writer.println("Thomas"); + writer.println("A1001"); + writer.print("Admin"); + } catch (IOException e) { + e.printStackTrace(); + } + String filename = "testAdminData.txt"; + List testAdmins = Admin.readFromFile(filename); + + assertEquals(1, testAdmins.size()); + Admin admin = testAdmins.get(0); + assertEquals("Thomas", admin.getName()); + assertEquals("A1001", admin.getId()); + assertEquals("Admin", admin.getRole()); + Files.delete(Path.of(filename)); } } \ No newline at end of file