diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index e77cc76..8399712 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -1,7 +1,11 @@ package org.example; +import junit.framework.JUnit4TestCaseFacade; import org.junit.jupiter.api.Test; - +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; import java.util.List; import java.util.Map; @@ -465,4 +469,51 @@ class AdministrationTest { assertEquals(0, student.courseGrades.size()); } + + @Test + void testViewGradesFromStudent() { + Administration administration = new Administration(); + + Course course = sampleCourse; + administration.addCourse(course); + + Student stud = sampleStudent; + administration.addStudents(stud); + + administration.enrollStudentInCourse(stud.getStudentId(), course.getCourseID()); + stud.assignGrade(course,"12"); + + + String studentId = stud.getStudentId() ; + + Student student = administration.findStudentById(studentId) ; + + String printedOutput = null; + + if (student != null) { + + // Redirect System.out to capture printed output + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outputStream)); + + // Call the method under test + student.printGrades(); + + // Get the printed output + printedOutput = outputStream.toString().trim(); + + + } else { + System.out.println("Student with ID " + studentId + " not found."); + } + + + + assertEquals("Grades for Student ID: " + student.getStudentId() + ", Name: "+ student.getStudentName() + "\r\nCourse: Math (M101), Grade: 12", printedOutput); + + + } + + } +