From 946c76220d7cade933f1d06c809304995cbbfc13 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:21:40 +0100 Subject: [PATCH] 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(){