|
@ -25,4 +25,32 @@ class StudentTest { |
|
|
Files.delete(path); |
|
|
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<Student> 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)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |