From a3c4884f5ec4774dd0d92b0517662c8bb4048a30 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:49:20 +0100 Subject: [PATCH 1/2] refactoring: extracting sampleProfs in AdministrationTest file --- src/test/java/org/example/AdministrationTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index e0f1c10..17f65b3 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -10,11 +10,13 @@ class AdministrationTest { 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"); + private static final Professor sampleProf = new Professor("P1001", "Aaron Levi", "Professor"); + private static final Professor sampleProf2 = new Professor("P1002", "Diana Richter", "Professor"); // Test the findProfessorById Method @Test void findProfessorById() { - Professor prof1 = new Professor("P1001", "Aaron", "Professor"); + Professor prof1 = sampleProf; admin.addProfessor(prof1); @@ -26,7 +28,7 @@ class AdministrationTest { @Test void deleteProfessor() { Administration administration = new Administration(); - Professor professor = new Professor("P1002", "Diana", "Professor"); + Professor professor = sampleProf2; administration.addProfessor(professor); assertTrue(administration.deleteProfessor("P1002")); @@ -37,11 +39,11 @@ class AdministrationTest { void testAddProfessor() { Administration administration = new Administration(); - Professor newProfessor = new Professor("P2001", "Dr. Jane Smith", "Professor"); + Professor newProfessor = sampleProf2; administration.addProfessor(newProfessor); - Professor retrievedProfessor = administration.findProfessorById("P2001"); + Professor retrievedProfessor = administration.findProfessorById("P1002"); assertNotNull(retrievedProfessor, "Professor should be found in the administration."); assertEquals(newProfessor.getProfessorID(), retrievedProfessor.getProfessorID(), "The retrieved professor's ID should match the original."); From 4c54c416ff7c98e8da1ce73fa8c83faf434a46fd Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 16:51:37 +0100 Subject: [PATCH 2/2] refactoring: extracting sampleAdmins in AdministrationTest file --- src/test/java/org/example/AdministrationTest.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 17f65b3..6f24b85 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -12,6 +12,8 @@ class AdministrationTest { private static final Student sampleStudent2 = new Student("Jesse Pinkman", "S789012", "Student"); private static final Professor sampleProf = new Professor("P1001", "Aaron Levi", "Professor"); private static final Professor sampleProf2 = new Professor("P1002", "Diana Richter", "Professor"); + private static final Admin sampleAdmin = new Admin("Saul Goodman", "A123456", "Admin"); + private static final Admin sampleAdmin2 = new Admin("Mike Unknown", "A789012", "Admin"); // Test the findProfessorById Method @Test @@ -95,13 +97,9 @@ class AdministrationTest { */ @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); + admin.addAdmin(sampleAdmin); + admin.addAdmin(sampleAdmin2); // Attempt to delete an admin (admin1) boolean deleted = admin.deleteAdmin("A123456");