From 628b3de9cd7ceb503e39eae1ba22345e66e8a2d4 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:28:13 +0100 Subject: [PATCH 01/11] Adding new courses List in Administration class --- src/main/java/org/example/Administration.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 8e6053b..27bdc9d 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -11,6 +11,7 @@ public class Administration { private List professors; private List admins; private List students; + private List courses; Scanner scanner = new Scanner(System.in); /** @@ -21,6 +22,7 @@ public class Administration { this.professors = new ArrayList<>(); this.admins = new ArrayList<>(); this.students = new ArrayList<>(); + this.courses = new ArrayList<>(); } From 3462d828f92108f3fe61f39a63633ff8d2cf5ce6 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:30:16 +0100 Subject: [PATCH 02/11] Adding addCourse method in Administration class --- src/main/java/org/example/Administration.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 27bdc9d..eedd0f4 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -26,6 +26,10 @@ public class Administration { } + public void addCourse(Course course){ + courses.add(course); + } + /** * * @param professorID the id of the professor you want to be deleted from the system From 71e4b58bbb8bf44ff86cf1f0df4e8e94e826b231 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:33:09 +0100 Subject: [PATCH 03/11] Adding deleteCourse method in Administration class --- src/main/java/org/example/Administration.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index eedd0f4..ad600be 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -30,6 +30,16 @@ public class Administration { courses.add(course); } + public boolean deleteCourse(String courseID){ + for(Course course : courses){ + if(course.getCourseCode().equals(courseID)){ + courses.remove(course); + return true; + } + } + return false; + } + /** * * @param professorID the id of the professor you want to be deleted from the system From 85e0713fd9a70e37688170e10a7ac4829f470810 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:35:32 +0100 Subject: [PATCH 04/11] Adding findCourseByID method in Administration class --- src/main/java/org/example/Administration.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index ad600be..2be4f6a 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -40,6 +40,15 @@ public class Administration { return false; } + public Course findCourseByID(String courseID){ + for(Course course : courses){ + if(course.getCourseCode().equals(courseID)){ + return course; + } + } + return null; + } + /** * * @param professorID the id of the professor you want to be deleted from the system @@ -86,8 +95,6 @@ public class Administration { } - - /** * * @param adminID the id of the admin you want to be deleted from the system From cdfe6d3ddb62c2df07e3e4c60256ad36d0412946 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:38:04 +0100 Subject: [PATCH 05/11] Finalizing documentation in Administration class --- src/main/java/org/example/Administration.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 2be4f6a..f760a50 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -26,10 +26,21 @@ public class Administration { } + /** + * Adds a course to the list of courses. + * + * @param course The course to be added. + */ public void addCourse(Course course){ courses.add(course); } + /** + * Deletes a course from the list of courses based on its course ID. + * + * @param courseID The course ID of the course to be deleted. + * @return true if the course is successfully deleted, false otherwise. + */ public boolean deleteCourse(String courseID){ for(Course course : courses){ if(course.getCourseCode().equals(courseID)){ @@ -40,6 +51,12 @@ public class Administration { return false; } + /** + * Finds a course in the list of courses based on its course ID. + * + * @param courseID The course ID of the course to be found. + * @return The course with the specified course ID, or null if not found. + */ public Course findCourseByID(String courseID){ for(Course course : courses){ if(course.getCourseCode().equals(courseID)){ From eb068791f3d4bb1a7753492c87844b7252bfcc3c Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:46:33 +0100 Subject: [PATCH 06/11] test: addCourse in Administration class --- src/test/java/org/example/AdministrationTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 26b22f9..e4ac41f 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -72,4 +72,11 @@ class AdministrationTest { assertEquals(student, student2); } + @Test + void addCourse() { + Administration admin = new Administration(); + Course course = new Course("Math", "M101", 4); + admin.addCourse(course); + assertEquals(course, admin.findCourseByID("M101")); + } } \ No newline at end of file From 5d8f186caad214ef12376dd4914fde1847f502b0 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:48:53 +0100 Subject: [PATCH 07/11] test: deleteCourse method in Administration class --- src/test/java/org/example/AdministrationTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index e4ac41f..20e879b 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -79,4 +79,19 @@ class AdministrationTest { admin.addCourse(course); assertEquals(course, admin.findCourseByID("M101")); } + + @Test + public void testDeleteCourse() { + Administration administration = new Administration(); + // Adding a course + Course course = new Course("Math", "M101", 4); + administration.addCourse(course); + + // Deleting the course + assertTrue(administration.deleteCourse("M101")); + + // Checking if the course is no longer found + assertNull(administration.findCourseByID("M101")); + } + } \ No newline at end of file From a28ac10f40f7360220c0dd4a64d22f1cca1134b9 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:51:09 +0100 Subject: [PATCH 08/11] test: findCourseByID method in Administration class --- src/test/java/org/example/AdministrationTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 20e879b..b5aa94f 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -94,4 +94,15 @@ class AdministrationTest { assertNull(administration.findCourseByID("M101")); } + @Test + public void testFindCourseByID() { + Administration administration = new Administration(); + // Adding a course + Course course = new Course("Math", "M101", 4); + administration.addCourse(course); + + // Finding the added course + assertEquals(course, administration.findCourseByID("M101")); + } + } \ No newline at end of file From 6cc661011fb923f5173f1457f1543f9d17c37582 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:52:31 +0100 Subject: [PATCH 09/11] Finalizing documentation in AdministrationTest file --- src/test/java/org/example/AdministrationTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index b5aa94f..b223cf4 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -72,6 +72,10 @@ class AdministrationTest { 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() { Administration admin = new Administration(); @@ -80,6 +84,10 @@ class AdministrationTest { 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() { Administration administration = new Administration(); @@ -94,6 +102,10 @@ class AdministrationTest { assertNull(administration.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() { Administration administration = new Administration(); From fc6f04db7b8bd081c94e91ce4f4f5f6860c409d3 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:54:38 +0100 Subject: [PATCH 10/11] refactoring: extract sampleCourse 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 b223cf4..ef6ebcb 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -6,6 +6,8 @@ import static org.junit.jupiter.api.Assertions.*; class AdministrationTest { + private static final Course sampleCourse = new Course("Math", "M101", 4); + // Test the findProfessorById Method @Test void findProfessorById() { @@ -79,7 +81,7 @@ class AdministrationTest { @Test void addCourse() { Administration admin = new Administration(); - Course course = new Course("Math", "M101", 4); + Course course = sampleCourse; admin.addCourse(course); assertEquals(course, admin.findCourseByID("M101")); } @@ -92,7 +94,7 @@ class AdministrationTest { public void testDeleteCourse() { Administration administration = new Administration(); // Adding a course - Course course = new Course("Math", "M101", 4); + Course course = sampleCourse; administration.addCourse(course); // Deleting the course @@ -110,7 +112,7 @@ class AdministrationTest { public void testFindCourseByID() { Administration administration = new Administration(); // Adding a course - Course course = new Course("Math", "M101", 4); + Course course = sampleCourse; administration.addCourse(course); // Finding the added course From 1a1504ac1477edeed06b66a3a2daadb004558a6e Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 15:57:56 +0100 Subject: [PATCH 11/11] refactoring: extracting admin object in AdministrationTest file --- .../java/org/example/AdministrationTest.java | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index ef6ebcb..a5d4da5 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -6,17 +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); @@ -26,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 @@ -35,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 @@ -47,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); @@ -65,12 +63,11 @@ 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); } @@ -80,7 +77,6 @@ class AdministrationTest { */ @Test void addCourse() { - Administration admin = new Administration(); Course course = sampleCourse; admin.addCourse(course); assertEquals(course, admin.findCourseByID("M101")); @@ -92,16 +88,15 @@ class AdministrationTest { */ @Test public void testDeleteCourse() { - Administration administration = new Administration(); // Adding a course Course course = sampleCourse; - administration.addCourse(course); + admin.addCourse(course); // Deleting the course - assertTrue(administration.deleteCourse("M101")); + assertTrue(admin.deleteCourse("M101")); // Checking if the course is no longer found - assertNull(administration.findCourseByID("M101")); + assertNull(admin.findCourseByID("M101")); } /** @@ -110,13 +105,12 @@ class AdministrationTest { */ @Test public void testFindCourseByID() { - Administration administration = new Administration(); // Adding a course Course course = sampleCourse; - administration.addCourse(course); + admin.addCourse(course); // Finding the added course - assertEquals(course, administration.findCourseByID("M101")); + assertEquals(course, admin.findCourseByID("M101")); } } \ No newline at end of file