Browse Source

Added test for printStudentInfo Method for Student class

remotes/origin/fdai7780
fdai7887 11 months ago
parent
commit
268bac6c43
  1. 23
      src/test/java/org/example/StudentTest.java

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

@ -26,7 +26,11 @@ class StudentTest {
} }
@Test
@Test
void readFromFile() throws IOException { void readFromFile() throws IOException {
try (PrintWriter writer = new PrintWriter(new FileWriter("testStudentData.txt"))){ try (PrintWriter writer = new PrintWriter(new FileWriter("testStudentData.txt"))){
@ -51,6 +55,23 @@ class StudentTest {
} }
@Test
void printStudentInfo() {
Student student = new Student("Sebastian", "S1001", "Student");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStream));
student.printStudentInfo();
String printedOutput = outputStream.toString().trim();
assertTrue(printedOutput.contains("Sebastian"));
assertTrue(printedOutput.contains("S1001"));
assertTrue(printedOutput.contains("Student"));
}
} }
Loading…
Cancel
Save