From ec0b692ce716b1a1a0692f0e445b672f4e84c3fe Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Thu, 8 Feb 2024 19:51:00 +0100 Subject: [PATCH] test: Added enrollInCourse Test Function --- .../java/org/example/AdministrationTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 819012e..4d2d885 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -2,6 +2,8 @@ package org.example; import org.junit.jupiter.api.Test; +import java.util.List; + import static org.junit.jupiter.api.Assertions.*; class AdministrationTest { @@ -274,4 +276,52 @@ class AdministrationTest { } + @Test + void testEnrollProfInCourse() { + Administration administration = new Administration(); + + //Professor who is about to get enrolled in a course + Professor professor = new Professor("P1001", "Alex", "Professor" ); + administration.addProfessor(professor); + + //The "User input" to determine the professor + String profID = professor.getProfessorID(); + + //Course the professor is being enrolled in + Course course = new Course("Swag", "C101", 5); + administration.addCourse(course); + + //The "User input" to determine the course + String courseID = course.getCourseID(); + + + Professor professorFound = administration.findProfessorById(profID); + Course courseFound = administration.findCourseByID(courseID); + + //Grabs the coursesTaught List from the Professor the user wants to enroll + List courseList = professorFound.getCoursesTaught(); + //Assigning the course to the Prof by adding it the to the courseList + courseList.add(course); + //The Professor gets the updated courseList + professorFound.setCoursesTaught(courseList); + + //Grabs the courseTaught List from the created Professor + List checkList = professor.getCoursesTaught(); + boolean hasCourse = false; + + //Checks if this List no contains the newly added course + for (Course courseSearch : checkList) + { + if(courseSearch.getCourseID() == courseID) + { + hasCourse = true; + } + + } + //If true everything worked + assertTrue(hasCourse); + + } + +}