Browse Source

Merge branch 'fdai7921' into 'master'

Fdai7921

See merge request fdai7600/PWN_Alpha_Dogs!8
remotes/origin/fdai7780
fdai7921 11 months ago
parent
commit
a2e11a7811
  1. 97
      src/test/java/org/example/AdministrationTest.java

97
src/test/java/org/example/AdministrationTest.java

@ -8,6 +8,8 @@ class AdministrationTest {
Administration admin = new Administration();
private static final Course sampleCourse = new Course("Math", "M101", 4);
private static final Student sampleStudent = new Student("Walter White", "S123456", "Student");
private static final Student sampleStudent2 = new Student("Jesse Pinkman", "S789012", "Student");
// Test the findProfessorById Method
@Test
@ -84,6 +86,40 @@ class AdministrationTest {
assertEquals(false, test02);
assertEquals(false, test03);
}
/**
* Test method for {@link Administration#deleteAdmin(String)}.
* Verifies the functionality of deleting an admin from the system.
*/
@Test
void deleteAdmin() {
// Create some sample admins
Admin admin1 = new Admin("Saul Goodman", "A123456", "Admin");
Admin admin2 = new Admin("Mike Unknown", "A789012", "Admin");
// Add admins to the administration
admin.addAdmin(admin1);
admin.addAdmin(admin2);
// Attempt to delete an admin (admin1)
boolean deleted = admin.deleteAdmin("A123456");
// Check if the admin is deleted successfully
assertTrue(deleted);
// Check if the admin is no longer in the system
assertNull(admin.findAdminById("A123456"));
// Check if the other admin (admin2) still exists in the system
assertNotNull(admin.findAdminById("A789012"));
// Attempt to delete a non-existing admin
boolean nonExistingAdminDeleted = admin.deleteAdmin("A999999");
// Check if the deletion of non-existing admin returns false
assertFalse(nonExistingAdminDeleted);
}
@org.junit.jupiter.api.Test
void findStudentById(){
@ -109,6 +145,66 @@ class AdministrationTest {
/**
* Test method for {@link Administration#addStudents(Student)}.
* Verifies the functionality of adding a student to the system.
*/
@Test
void addStudents() {
// Creating a sample student
Student student = sampleStudent;
// Adding the student to the system
admin.addStudents(student);
// Retrieving the added student by ID
Student retrievedStudent = admin.findStudentById("S123456");
// Asserting that the retrieved student is not null
assertNotNull(retrievedStudent);
// Asserting that the retrieved student's name matches the expected name
assertEquals("Walter White", retrievedStudent.getName());
// Asserting that the retrieved student's ID matches the expected ID
assertEquals("S123456", retrievedStudent.getId());
// Asserting that the retrieved student's role matches the expected role
assertEquals("Student", retrievedStudent.getRole());
}
/**
* Test method for {@link Administration#deleteStudents(String)}.
* Verifies the functionality of deleting a student from the system.
*/
@Test
void deleteStudents() {
Student student1 = sampleStudent;
Student student2 = sampleStudent2;
// Add students to the administration
admin.addStudents(student1);
admin.addStudents(student2);
// Delete a student (student1)
boolean deleted = admin.deleteStudents("S123456");
// Check if the student is deleted successfully
assertTrue(deleted);
// Check if the student is no longer in the system
assertNull(admin.findStudentById("S123456"));
// Check if the other student (student2) still exists in the system
assertNotNull(admin.findStudentById("S789012"));
// Attempt to delete a non-existing student
boolean nonExistingStudentDeleted = admin.deleteStudents("S999999");
// Check if the deletion of non-existing student returns false
assertFalse(nonExistingStudentDeleted);
}
/**
* Test case for the addCourse method.
* Adds a course to the Administration instance and checks if it can be found by its ID.
@ -150,5 +246,4 @@ class AdministrationTest {
// Finding the added course
assertEquals(course, admin.findCourseByID("M101"));
}
}
Loading…
Cancel
Save