Browse Source

Added test for readFromFile to StudentTest class

remotes/origin/fdai7780
fdai7887 11 months ago
parent
commit
2496df464c
  1. 28
      src/test/java/org/example/StudentTest.java

28
src/test/java/org/example/StudentTest.java

@ -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));
}
} }
Loading…
Cancel
Save