|
|
@ -6,15 +6,17 @@ import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
class AdministrationTest { |
|
|
|
|
|
|
|
Administration admin = new Administration(); |
|
|
|
private static final Course sampleCourse = new Course("Math", "M101", 4); |
|
|
|
|
|
|
|
// Test the findProfessorById Method |
|
|
|
@Test |
|
|
|
void findProfessorById() { |
|
|
|
Administration administration = new Administration(); |
|
|
|
Professor prof1 = new Professor("P1001", "Aaron", "Professor"); |
|
|
|
|
|
|
|
administration.addProfessor(prof1); |
|
|
|
admin.addProfessor(prof1); |
|
|
|
|
|
|
|
Professor foundProf1 = administration.findProfessorById("P1001"); |
|
|
|
Professor foundProf1 = admin.findProfessorById("P1001"); |
|
|
|
assertEquals(prof1, foundProf1); |
|
|
|
|
|
|
|
|
|
|
@ -24,7 +26,6 @@ class AdministrationTest { |
|
|
|
@Test |
|
|
|
void isNumber() { |
|
|
|
|
|
|
|
Administration administration = new Administration(); |
|
|
|
String full01 = "S1002"; //Supposed student id |
|
|
|
// String str1 = full01.substring(1); //String without the Letter |
|
|
|
String full02 = "S100Z"; //Supposed student id |
|
|
@ -33,9 +34,9 @@ class AdministrationTest { |
|
|
|
// String str3 = full03.substring(1); //String without the Letter |
|
|
|
|
|
|
|
//checks if the substrings contain only digits |
|
|
|
boolean test01 = administration.isNumber(full01); |
|
|
|
boolean test02 = administration.isNumber(full02); |
|
|
|
boolean test03 = administration.isNumber(full03); |
|
|
|
boolean test01 = admin.isNumber(full01); |
|
|
|
boolean test02 = admin.isNumber(full02); |
|
|
|
boolean test03 = admin.isNumber(full03); |
|
|
|
|
|
|
|
assertEquals(true, test01); //only digits besides the first letter |
|
|
|
assertEquals(false, test02); // false, because the Z at the end |
|
|
@ -45,16 +46,15 @@ class AdministrationTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
void rightPrefix() { |
|
|
|
Administration administration = new Administration(); |
|
|
|
|
|
|
|
String full01 = "S1002"; //Supposed Student id |
|
|
|
String full02 = "s100Z"; //Supposed Student id |
|
|
|
String full03 = "X1004"; // Supposed Professor id |
|
|
|
|
|
|
|
|
|
|
|
boolean test01 = administration.rightPrefix(full01, 1); //checks if the id is correct, "1" because we are expecting a student id |
|
|
|
boolean test02 = administration.rightPrefix(full02, 1); //checks if the id is correct, "1" because we are expecting a student id |
|
|
|
boolean test03 = administration.rightPrefix(full03, 3); //checks if the id is correct, "3" because we are expecting a professor id |
|
|
|
boolean test01 = admin.rightPrefix(full01, 1); //checks if the id is correct, "1" because we are expecting a student id |
|
|
|
boolean test02 = admin.rightPrefix(full02, 1); //checks if the id is correct, "1" because we are expecting a student id |
|
|
|
boolean test03 = admin.rightPrefix(full03, 3); //checks if the id is correct, "3" because we are expecting a professor id |
|
|
|
|
|
|
|
assertEquals(true, test01); |
|
|
|
assertEquals(false, test02); |
|
|
@ -63,13 +63,54 @@ class AdministrationTest { |
|
|
|
@org.junit.jupiter.api.Test |
|
|
|
|
|
|
|
void findStudentById(){ |
|
|
|
Administration administration = new Administration(); |
|
|
|
Student student = new Student("Mark", "S1001", "Student"); |
|
|
|
|
|
|
|
administration.addStudents(student); |
|
|
|
admin.addStudents(student); |
|
|
|
|
|
|
|
Student student2 = administration.findStudentById("S1001"); |
|
|
|
Student student2 = admin.findStudentById("S1001"); |
|
|
|
assertEquals(student, student2); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Test case for the addCourse method. |
|
|
|
* Adds a course to the Administration instance and checks if it can be found by its ID. |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
void addCourse() { |
|
|
|
Course course = sampleCourse; |
|
|
|
admin.addCourse(course); |
|
|
|
assertEquals(course, admin.findCourseByID("M101")); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Test case for the deleteCourse method. |
|
|
|
* Adds a course, deletes it, and checks if it's no longer found. |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testDeleteCourse() { |
|
|
|
// Adding a course |
|
|
|
Course course = sampleCourse; |
|
|
|
admin.addCourse(course); |
|
|
|
|
|
|
|
// Deleting the course |
|
|
|
assertTrue(admin.deleteCourse("M101")); |
|
|
|
|
|
|
|
// Checking if the course is no longer found |
|
|
|
assertNull(admin.findCourseByID("M101")); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Test case for the findCourseByID method. |
|
|
|
* Adds a course and checks if it can be found by its ID. |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testFindCourseByID() { |
|
|
|
// Adding a course |
|
|
|
Course course = sampleCourse; |
|
|
|
admin.addCourse(course); |
|
|
|
|
|
|
|
// Finding the added course |
|
|
|
assertEquals(course, admin.findCourseByID("M101")); |
|
|
|
} |
|
|
|
|
|
|
|
} |