Browse Source

test: addCourse method in Course class

remotes/origin/fdai7780
fdai7921 11 months ago
parent
commit
91cd4439af
  1. 25
      src/test/java/org/example/CourseTest.java

25
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<Course> 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.
*

Loading…
Cancel
Save