From d682a91abb42405b440d1c2f725be700ed61ded2 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:08:22 +0100 Subject: [PATCH 1/5] test: deleteStudent method in Administration class --- .../java/org/example/AdministrationTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index a5d4da5..eef7af4 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -71,6 +71,34 @@ class AdministrationTest { assertEquals(student, student2); } + @Test + void deleteStudents() { + Student student1 = new Student("Walter White", "S123456", "Student"); + Student student2 = new Student("Jesse Pinkmann", "S789012", "Student"); + + // 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. From d0ad3ba87b4517d1991262bcf26492a3183140ff Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:18:41 +0100 Subject: [PATCH 2/5] test: addStudents method in Administration class --- .../java/org/example/AdministrationTest.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index eef7af4..6b2e3f7 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -71,6 +71,32 @@ class AdministrationTest { assertEquals(student, student2); } + @Test + void addStudents() { + Administration admin = new Administration(); + + // Creating a sample student + Student student = new Student("Walter White", "S123456", "Student"); + + // 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 void deleteStudents() { Student student1 = new Student("Walter White", "S123456", "Student"); @@ -140,5 +166,4 @@ class AdministrationTest { // Finding the added course assertEquals(course, admin.findCourseByID("M101")); } - } \ No newline at end of file From 946c76220d7cade933f1d06c809304995cbbfc13 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:21:40 +0100 Subject: [PATCH 3/5] test: deleteAdmin method in Administration class --- .../java/org/example/AdministrationTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 6b2e3f7..6bf3b3b 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -60,6 +60,39 @@ class AdministrationTest { assertEquals(false, test02); assertEquals(false, test03); } + + @Test + void deleteAdmin() { + // Create an instance of Administration + Administration administration = new Administration(); + + // 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 + administration.addAdmin(admin1); + administration.addAdmin(admin2); + + // Attempt to delete an admin (admin1) + boolean deleted = administration.deleteAdmin("A123456"); + + // Check if the admin is deleted successfully + assertTrue(deleted); + + // Check if the admin is no longer in the system + assertNull(administration.findAdminById("A123456")); + + // Check if the other admin (admin2) still exists in the system + assertNotNull(administration.findAdminById("A789012")); + + // Attempt to delete a non-existing admin + boolean nonExistingAdminDeleted = administration.deleteAdmin("A999999"); + + // Check if the deletion of non-existing admin returns false + assertFalse(nonExistingAdminDeleted); + } + @org.junit.jupiter.api.Test void findStudentById(){ From 90d518e61e850f036776a6f69a5071d172dd8127 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:24:26 +0100 Subject: [PATCH 4/5] Finalizing documentation and simplify admin object handling in AdministrationTest file --- .../java/org/example/AdministrationTest.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 6bf3b3b..4eec884 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -61,33 +61,34 @@ class AdministrationTest { assertEquals(false, test03); } + /** + * Test method for {@link Administration#deleteAdmin(String)}. + * Verifies the functionality of deleting an admin from the system. + */ @Test void deleteAdmin() { - // Create an instance of Administration - Administration administration = new Administration(); - // 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 - administration.addAdmin(admin1); - administration.addAdmin(admin2); + admin.addAdmin(admin1); + admin.addAdmin(admin2); // Attempt to delete an admin (admin1) - boolean deleted = administration.deleteAdmin("A123456"); + 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(administration.findAdminById("A123456")); + assertNull(admin.findAdminById("A123456")); // Check if the other admin (admin2) still exists in the system - assertNotNull(administration.findAdminById("A789012")); + assertNotNull(admin.findAdminById("A789012")); // Attempt to delete a non-existing admin - boolean nonExistingAdminDeleted = administration.deleteAdmin("A999999"); + boolean nonExistingAdminDeleted = admin.deleteAdmin("A999999"); // Check if the deletion of non-existing admin returns false assertFalse(nonExistingAdminDeleted); @@ -104,10 +105,12 @@ class AdministrationTest { assertEquals(student, student2); } + /** + * Test method for {@link Administration#addStudents(Student)}. + * Verifies the functionality of adding a student to the system. + */ @Test void addStudents() { - Administration admin = new Administration(); - // Creating a sample student Student student = new Student("Walter White", "S123456", "Student"); @@ -130,6 +133,10 @@ class AdministrationTest { 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 = new Student("Walter White", "S123456", "Student"); From f4db111d22f69aaf456f319bccc6383df5900a7a Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:28:13 +0100 Subject: [PATCH 5/5] refactoring: extracting sampleStudents in AdministrationTest file --- src/test/java/org/example/AdministrationTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 4eec884..ad18cd2 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/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 @@ -112,7 +114,7 @@ class AdministrationTest { @Test void addStudents() { // Creating a sample student - Student student = new Student("Walter White", "S123456", "Student"); + Student student = sampleStudent; // Adding the student to the system admin.addStudents(student); @@ -139,8 +141,8 @@ class AdministrationTest { */ @Test void deleteStudents() { - Student student1 = new Student("Walter White", "S123456", "Student"); - Student student2 = new Student("Jesse Pinkmann", "S789012", "Student"); + Student student1 = sampleStudent; + Student student2 = sampleStudent2; // Add students to the administration admin.addStudents(student1);