From 91cd4439af8008ab9bd5d53f41ad35dc2e865d5a Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 13:24:00 +0100 Subject: [PATCH] test: addCourse method in Course class --- src/test/java/org/example/CourseTest.java | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/java/org/example/CourseTest.java b/src/test/java/org/example/CourseTest.java index 01bd09d..5438509 100644 --- a/src/test/java/org/example/CourseTest.java +++ b/src/test/java/org/example/CourseTest.java @@ -107,6 +107,31 @@ class CourseTest { deleteTempFile(); } + @Test + void addCourse() { + // Create a new course + String courseName = "Math"; + String courseCode = "C101"; + int courseCredit = 3; + + // Write course data to the temporary file + Course.addCourse(courseName, courseCode, courseCredit, TEMP_FILE); + + // Read course data from the temporary file + List courses = Course.readFromFile(TEMP_FILE); + + // Assert that the course is added successfully + assertEquals(1, courses.size()); + Course addedCourse = courses.get(0); + assertEquals(courseName, addedCourse.getCourseName()); + assertEquals(courseCode, addedCourse.getCourseCode()); + assertEquals(courseCredit, addedCourse.getCourseCredit()); + + // Delete the temporary file + deleteTempFile(); + } + + /** * Creates a temporary file with the provided data. *