|
|
@ -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; |
|
|
|
|
|
|
@ -123,7 +127,7 @@ class AdministrationTest { |
|
|
|
assertFalse(nonExistingAdminDeleted); |
|
|
|
} |
|
|
|
|
|
|
|
@org.junit.jupiter.api.Test |
|
|
|
@Test |
|
|
|
|
|
|
|
void testFindStudentById(){ |
|
|
|
Student student = new Student("Mark", "S1001", "Student"); |
|
|
@ -447,4 +451,51 @@ class AdministrationTest { |
|
|
|
|
|
|
|
assertTrue(correct); |
|
|
|
} |
|
|
|
|
|
|
|
@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); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|