|
|
@ -10,9 +10,11 @@ import java.util.List; |
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
class StudentTest { |
|
|
|
|
|
|
|
private static final Student sampleStudent = new Student("Sebastian Reichard", "S1001", "Student"); |
|
|
|
|
|
|
|
@org.junit.jupiter.api.Test |
|
|
|
void writeToFile() throws IOException { |
|
|
|
Student student = new Student("Sebastian", "S1001", "Student") ; |
|
|
|
Student student = sampleStudent; |
|
|
|
|
|
|
|
String filename = "testStudentData.txt"; |
|
|
|
|
|
|
@ -20,7 +22,7 @@ class StudentTest { |
|
|
|
|
|
|
|
Path path = Path.of(filename); |
|
|
|
String content = Files.readString(path); |
|
|
|
assertEquals("Sebastian\nS1001\nStudent", content); |
|
|
|
assertEquals("Sebastian Reichard\nS1001\nStudent", content); |
|
|
|
|
|
|
|
Files.delete(path); |
|
|
|
|
|
|
@ -34,7 +36,7 @@ class StudentTest { |
|
|
|
void readFromFile() throws IOException { |
|
|
|
|
|
|
|
try (PrintWriter writer = new PrintWriter(new FileWriter("testStudentData.txt"))){ |
|
|
|
writer.println("Samuel"); |
|
|
|
writer.println("Sebastian Reichard"); |
|
|
|
writer.println("S1001"); |
|
|
|
writer.print("Student"); |
|
|
|
} catch (IOException e) { |
|
|
@ -46,7 +48,7 @@ class StudentTest { |
|
|
|
assertEquals(1, testStudents.size()); |
|
|
|
Student admin = testStudents.get(0); |
|
|
|
|
|
|
|
assertEquals("Samuel", admin.getName()); |
|
|
|
assertEquals("Sebastian Reichard", admin.getName()); |
|
|
|
assertEquals("S1001", admin.getId()); |
|
|
|
assertEquals("Student", admin.getRole()); |
|
|
|
|
|
|
@ -57,7 +59,7 @@ class StudentTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
void printStudentInfo() { |
|
|
|
Student student = new Student("Sebastian", "S1001", "Student"); |
|
|
|
Student student = sampleStudent; |
|
|
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
System.setOut(new PrintStream(outputStream)); |
|
|
@ -66,7 +68,7 @@ class StudentTest { |
|
|
|
|
|
|
|
String printedOutput = outputStream.toString().trim(); |
|
|
|
|
|
|
|
assertTrue(printedOutput.contains("Sebastian")); |
|
|
|
assertTrue(printedOutput.contains("Sebastian Reichard")); |
|
|
|
assertTrue(printedOutput.contains("S1001")); |
|
|
|
assertTrue(printedOutput.contains("Student")); |
|
|
|
|
|
|
|