|
|
@ -24,7 +24,7 @@ class CourseTest { |
|
|
|
* Verifies that the method correctly prints course information to the console. |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
void printCourseInfo() { |
|
|
|
void testPrintCourseInfo() { |
|
|
|
// Set up the expected output |
|
|
|
String expectedCourseName = "Course Name: Math"; |
|
|
|
String expectedCourseCode = "Course Code: M101"; |
|
|
@ -58,12 +58,12 @@ class CourseTest { |
|
|
|
* Verifies that course data is correctly written to a file and can be read back. |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
void writeToFile() { |
|
|
|
void testWriteToFile() { |
|
|
|
// Create a new course |
|
|
|
Course course = sampleCourse; |
|
|
|
|
|
|
|
// Write course data to the temporary file |
|
|
|
course.writeToFile(course.getCourseName(), course.getCourseCode(), course.getCourseCredit(), TEMP_FILE); |
|
|
|
course.writeToFile(course.getCourseName(), course.getCourseID(), course.getCourseCredits(), TEMP_FILE); |
|
|
|
|
|
|
|
// Read course data from the temporary file |
|
|
|
List<Course> courses = Course.readFromFile(TEMP_FILE); |
|
|
@ -72,8 +72,8 @@ class CourseTest { |
|
|
|
assertEquals(1, courses.size()); |
|
|
|
Course readCourse = courses.get(0); |
|
|
|
assertEquals("Math", readCourse.getCourseName()); |
|
|
|
assertEquals("M101", readCourse.getCourseCode()); |
|
|
|
assertEquals(3, readCourse.getCourseCredit()); |
|
|
|
assertEquals("M101", readCourse.getCourseID()); |
|
|
|
assertEquals(3, readCourse.getCourseCredits()); |
|
|
|
|
|
|
|
// Delete the temporary file |
|
|
|
deleteTempFile(); |
|
|
@ -84,7 +84,7 @@ class CourseTest { |
|
|
|
* Verifies that course data can be correctly read from a file. |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
void readFromFile() { |
|
|
|
void testReadFromFile() { |
|
|
|
// Create a temporary file with sample course data |
|
|
|
createTempFile("Math", "C101", "3", "Science", "C201", "4"); |
|
|
|
|
|
|
@ -96,24 +96,24 @@ class CourseTest { |
|
|
|
|
|
|
|
Course course1 = courses.get(0); |
|
|
|
assertEquals("Math", course1.getCourseName()); |
|
|
|
assertEquals("C101", course1.getCourseCode()); |
|
|
|
assertEquals(3, course1.getCourseCredit()); |
|
|
|
assertEquals("C101", course1.getCourseID()); |
|
|
|
assertEquals(3, course1.getCourseCredits()); |
|
|
|
|
|
|
|
Course course2 = courses.get(1); |
|
|
|
assertEquals("Science", course2.getCourseName()); |
|
|
|
assertEquals("C201", course2.getCourseCode()); |
|
|
|
assertEquals(4, course2.getCourseCredit()); |
|
|
|
assertEquals("C201", course2.getCourseID()); |
|
|
|
assertEquals(4, course2.getCourseCredits()); |
|
|
|
|
|
|
|
// Delete the temporary file |
|
|
|
deleteTempFile(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void addCourse() { |
|
|
|
void testAddCourse() { |
|
|
|
// Create a new course |
|
|
|
String courseName = sampleCourse.getCourseName(); |
|
|
|
String courseCode = sampleCourse.getCourseCode(); |
|
|
|
int courseCredit = sampleCourse.getCourseCredit(); |
|
|
|
String courseCode = sampleCourse.getCourseID(); |
|
|
|
int courseCredit = sampleCourse.getCourseCredits(); |
|
|
|
|
|
|
|
// Write course data to the temporary file |
|
|
|
Course.addCourse(courseName, courseCode, courseCredit, TEMP_FILE); |
|
|
@ -125,8 +125,8 @@ class CourseTest { |
|
|
|
assertEquals(1, courses.size()); |
|
|
|
Course addedCourse = courses.get(0); |
|
|
|
assertEquals(courseName, addedCourse.getCourseName()); |
|
|
|
assertEquals(courseCode, addedCourse.getCourseCode()); |
|
|
|
assertEquals(courseCredit, addedCourse.getCourseCredit()); |
|
|
|
assertEquals(courseCode, addedCourse.getCourseID()); |
|
|
|
assertEquals(courseCredit, addedCourse.getCourseCredits()); |
|
|
|
|
|
|
|
// Delete the temporary file |
|
|
|
deleteTempFile(); |
|
|
@ -137,14 +137,14 @@ class CourseTest { |
|
|
|
// Write courses to the test file |
|
|
|
PrintWriter writer = new PrintWriter(new FileWriter(TEMP_FILE)); |
|
|
|
writer.println(sampleCourse.getCourseName()); |
|
|
|
writer.println(sampleCourse.getCourseCode()); |
|
|
|
writer.println(sampleCourse.getCourseCredit()); |
|
|
|
writer.println(sampleCourse.getCourseID()); |
|
|
|
writer.println(sampleCourse.getCourseCredits()); |
|
|
|
writer.println(sampleCourse2.getCourseName()); |
|
|
|
writer.println(sampleCourse2.getCourseCode()); |
|
|
|
writer.println(sampleCourse2.getCourseCredit()); |
|
|
|
writer.println(sampleCourse2.getCourseID()); |
|
|
|
writer.println(sampleCourse2.getCourseCredits()); |
|
|
|
writer.println(sampleCourse3.getCourseName()); |
|
|
|
writer.println(sampleCourse3.getCourseCode()); |
|
|
|
writer.println(sampleCourse3.getCourseCredit()); |
|
|
|
writer.println(sampleCourse3.getCourseID()); |
|
|
|
writer.println(sampleCourse3.getCourseCredits()); |
|
|
|
writer.close(); |
|
|
|
|
|
|
|
// Simulate user input for course deletion |
|
|
|