From 2496df464cd13f9aba887e915e842a6b84c25ceb Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Tue, 6 Feb 2024 23:59:42 +0100 Subject: [PATCH] Added test for readFromFile to StudentTest class --- src/test/java/org/example/StudentTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/org/example/StudentTest.java b/src/test/java/org/example/StudentTest.java index e97e7d0..89d4d40 100644 --- a/src/test/java/org/example/StudentTest.java +++ b/src/test/java/org/example/StudentTest.java @@ -25,4 +25,32 @@ class StudentTest { Files.delete(path); } + +@Test + void readFromFile() throws IOException { + + try (PrintWriter writer = new PrintWriter(new FileWriter("testStudentData.txt"))){ + writer.println("Samuel"); + writer.println("S1001"); + writer.print("Student"); + } catch (IOException e) { + e.printStackTrace(); + } + String filename = "testStudentData.txt"; + List testStudents = Student.readFromFile(filename); + + assertEquals(1, testStudents.size()); + Student admin = testStudents.get(0); + + assertEquals("Samuel", admin.getName()); + assertEquals("S1001", admin.getId()); + assertEquals("Student", admin.getRole()); + + Files.delete(Path.of(filename)); + + } + + + + } \ No newline at end of file