From f94d4419b92f9b6aa8117b84582057f459b814c2 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:57:58 +0100 Subject: [PATCH] extracting sample student in StudentTest file --- src/test/java/org/example/StudentTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/example/StudentTest.java b/src/test/java/org/example/StudentTest.java index 256b017..2bac26a 100644 --- a/src/test/java/org/example/StudentTest.java +++ b/src/test/java/org/example/StudentTest.java @@ -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"));