diff --git a/src/test/java/org/example/CourseTest.java b/src/test/java/org/example/CourseTest.java index 5445a3d..0a7d241 100644 --- a/src/test/java/org/example/CourseTest.java +++ b/src/test/java/org/example/CourseTest.java @@ -6,6 +6,9 @@ import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import static org.junit.Assert.assertEquals; +import java.io.*; +import java.util.List; + class CourseTest { @@ -41,4 +44,32 @@ class CourseTest { assertEquals(expectedCourseCode, outputLines[1].trim()); assertEquals(expectedCourseCredits, outputLines[2].trim()); } + + @Test + void writeToFile() { + // Create a temporary file for testing + String filename = "test_course_data.txt"; + + // Create a new course + Course course = new Course("Math", "C101", 3); + + // Write course data to the temporary file + course.writeToFile(filename); + + // Read course data from the temporary file + List courses = Course.readFromFile(filename); + + // Assert that the read data matches the original course + assertEquals(1, courses.size()); + Course readCourse = courses.get(0); + assertEquals("Math", readCourse.getCourseName()); + assertEquals(3, readCourse.getCourseCredit()); + + // Delete the temporary file + File file = new File(filename); + if (file.exists()) { + file.delete(); + } + + } } \ No newline at end of file