Fakultas Ilmu Komputer UI

Commit f609a713 authored by saddamonpc's avatar saddamonpc
Browse files

Update @BeforeEach and Initialize @AfterEach for every tests

parent 2f6f4dd7
Pipeline #81775 passed with stage
in 2 minutes and 15 seconds
...@@ -56,7 +56,7 @@ public class Main { ...@@ -56,7 +56,7 @@ public class Main {
CourseList courseList; CourseList courseList;
UserList userList; UserList userList;
//--------Uncomment all of this for the "hardcoded" version. // --------Uncomment all of this for the "hardcoded" version.
// Uncomment to add a new fresh userList and courseList // Uncomment to add a new fresh userList and courseList
courseList = new CourseList(); courseList = new CourseList();
userList = new UserList(); userList = new UserList();
......
package softeng.g4; package softeng.g4;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import softeng.g4.cli.ListIO;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
import softeng.g4.user.Admin;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class MainTest { class MainTest {
private UserList userList;
private CourseList courseList;
private Admin testAdmin;
private TeachingAssistant testTa;
private Student testStudent;
@BeforeEach
void setUpTearDown() {
userList = new UserList();
courseList = new CourseList();
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
testAdmin = new Admin("testAdmin", "Test Admin", userList);
testTa = new TeachingAssistant("testTa",
"Test Teacher", Long.parseLong("123456789"), userList);
testStudent = new Student("testStudent",
"Test Student", Long.valueOf("123456789"), userList);
}
@Test @Test
void main() { void main() {
} }
...@@ -13,4 +45,42 @@ class MainTest { ...@@ -13,4 +45,42 @@ class MainTest {
@Test @Test
void intro() { void intro() {
} }
@AfterEach
void finalTearDown() {
courseList = new CourseList();
userList = new UserList();
// Uncomment here to add a new TA or Admin
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
// Add testStudent
new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList);
// Add testTa with a mock calendar and schedule
TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList);
testTa.setSchedule("monday", "Free", "12:00", "17:00");
testTa.setSchedule("tuesday", "Free", "08:00", "11:00");
testTa.setSchedule("tuesday", "Free", "12:00", "15:00");
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Free", "12:00", "17:00");
new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList);
// Add testAdmin
new Admin("akuAdmin", "Aku Admin", userList);
// Add false course
new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList);
// Add mock courses
new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList);
new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList);
new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList);
// Save the course
ListIO.saveList(courseList, userList);
}
} }
\ No newline at end of file
package softeng.g4.cli; package softeng.g4.cli;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
import softeng.g4.user.Admin;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class AdminCLITest { class AdminCLITest {
private UserList userList;
private CourseList courseList;
private Admin testAdmin;
private TeachingAssistant testTa;
private Student testStudent;
@BeforeEach
void setUpTearDown() {
userList = new UserList();
courseList = new CourseList();
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
testAdmin = new Admin("testAdmin", "Test Admin", userList);
testTa = new TeachingAssistant("testTa",
"Test Teacher", Long.parseLong("123456789"), userList);
testStudent = new Student("testStudent",
"Test Student", Long.valueOf("123456789"), userList);
}
@Test @Test
void main() { void main() {
} }
...@@ -13,4 +45,42 @@ class AdminCLITest { ...@@ -13,4 +45,42 @@ class AdminCLITest {
@Test @Test
void intro() { void intro() {
} }
@AfterEach
void finalTearDown() {
courseList = new CourseList();
userList = new UserList();
// Uncomment here to add a new TA or Admin
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
// Add testStudent
new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList);
// Add testTa with a mock calendar and schedule
TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList);
testTa.setSchedule("monday", "Free", "12:00", "17:00");
testTa.setSchedule("tuesday", "Free", "08:00", "11:00");
testTa.setSchedule("tuesday", "Free", "12:00", "15:00");
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Free", "12:00", "17:00");
new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList);
// Add testAdmin
new Admin("akuAdmin", "Aku Admin", userList);
// Add false course
new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList);
// Add mock courses
new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList);
new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList);
new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList);
// Save the course
ListIO.saveList(courseList, userList);
}
} }
\ No newline at end of file
package softeng.g4.cli; package softeng.g4.cli;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
import softeng.g4.user.Admin;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class ListIOTest { class ListIOTest {
private UserList userList;
private CourseList courseList;
private Admin testAdmin;
private TeachingAssistant testTa;
private Student testStudent;
@BeforeEach
void setUpTearDown() {
userList = new UserList();
courseList = new CourseList();
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
testAdmin = new Admin("testAdmin", "Test Admin", userList);
testTa = new TeachingAssistant("testTa",
"Test Teacher", Long.parseLong("123456789"), userList);
testStudent = new Student("testStudent",
"Test Student", Long.valueOf("123456789"), userList);
}
@Test @Test
void openCourseList() { void openCourseList() {
courseList = ListIO.openCourseList();
assertEquals(courseList, courseList);
} }
@Test @Test
void openUserList() { void openUserList() {
userList = ListIO.openUserList();
assertEquals(userList, userList);
} }
@Test @Test
void saveList() { void saveList() {
new Admin("newTestAdmin", "New Test Admin", userList);
new TeachingAssistant("newTestTa",
"New Test Teacher", Long.parseLong("123456789"), userList);
new Student("newTestStudent",
"New Test Student", Long.valueOf("123456789"), userList);
new Course("test", "TEST", "Test Professor", 1, courseList);
ListIO.saveList(courseList, userList);
assertEquals(userList, userList);
assertEquals(courseList, courseList);
}
@AfterEach
void finalTearDown() {
courseList = new CourseList();
userList = new UserList();
// Uncomment here to add a new TA or Admin
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
// Add testStudent
new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList);
// Add testTa with a mock calendar and schedule
TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList);
testTa.setSchedule("monday", "Free", "12:00", "17:00");
testTa.setSchedule("tuesday", "Free", "08:00", "11:00");
testTa.setSchedule("tuesday", "Free", "12:00", "15:00");
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Free", "12:00", "17:00");
new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList);
// Add testAdmin
new Admin("akuAdmin", "Aku Admin", userList);
// Add false course
new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList);
// Add mock courses
new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList);
new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList);
new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList);
// Save the course
ListIO.saveList(courseList, userList);
} }
} }
\ No newline at end of file
package softeng.g4.cli; package softeng.g4.cli;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
import softeng.g4.user.Admin;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class StudentCLITest { class StudentCLITest {
private UserList userList;
private CourseList courseList;
private Admin testAdmin;
private TeachingAssistant testTa;
private Student testStudent;
@BeforeEach
void setUpTearDown() {
userList = new UserList();
courseList = new CourseList();
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
testAdmin = new Admin("testAdmin", "Test Admin", userList);
testTa = new TeachingAssistant("testTa",
"Test Teacher", Long.parseLong("123456789"), userList);
testStudent = new Student("testStudent",
"Test Student", Long.valueOf("123456789"), userList);
}
@Test @Test
void main() { void main() {
} }
...@@ -13,4 +45,42 @@ class StudentCLITest { ...@@ -13,4 +45,42 @@ class StudentCLITest {
@Test @Test
void intro() { void intro() {
} }
@AfterEach
void finalTearDown() {
courseList = new CourseList();
userList = new UserList();
// Uncomment here to add a new TA or Admin
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
// Add testStudent
new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList);
// Add testTa with a mock calendar and schedule
TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList);
testTa.setSchedule("monday", "Free", "12:00", "17:00");
testTa.setSchedule("tuesday", "Free", "08:00", "11:00");
testTa.setSchedule("tuesday", "Free", "12:00", "15:00");
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Free", "12:00", "17:00");
new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList);
// Add testAdmin
new Admin("akuAdmin", "Aku Admin", userList);
// Add false course
new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList);
// Add mock courses
new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList);
new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList);
new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList);
// Save the course
ListIO.saveList(courseList, userList);
}
} }
\ No newline at end of file
package softeng.g4.cli; package softeng.g4.cli;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
import softeng.g4.user.Admin;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class TACLITest { class TACLITest {
private UserList userList;
private CourseList courseList;
private Admin testAdmin;
private TeachingAssistant testTa;
private Student testStudent;
@BeforeEach
void setUpTearDown() {
userList = new UserList();
courseList = new CourseList();
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
testAdmin = new Admin("testAdmin", "Test Admin", userList);
testTa = new TeachingAssistant("testTa",
"Test Teacher", Long.parseLong("123456789"), userList);
testStudent = new Student("testStudent",
"Test Student", Long.valueOf("123456789"), userList);
}
@Test @Test
void main() { void main() {
} }
...@@ -13,4 +45,42 @@ class TACLITest { ...@@ -13,4 +45,42 @@ class TACLITest {
@Test @Test
void intro() { void intro() {
} }
@AfterEach
void finalTearDown() {
courseList = new CourseList();
userList = new UserList();
// Uncomment here to add a new TA or Admin
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
// Add testStudent
new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList);
// Add testTa with a mock calendar and schedule
TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList);
testTa.setSchedule("monday", "Free", "12:00", "17:00");
testTa.setSchedule("tuesday", "Free", "08:00", "11:00");
testTa.setSchedule("tuesday", "Free", "12:00", "15:00");
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Free", "12:00", "17:00");
new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList);
// Add testAdmin
new Admin("akuAdmin", "Aku Admin", userList);
// Add false course
new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList);
// Add mock courses
new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList);
new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList);
new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList);
// Save the course
ListIO.saveList(courseList, userList);
}
} }
\ No newline at end of file
package softeng.g4.user; package softeng.g4.user;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import softeng.g4.cli.ListIO;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList; import softeng.g4.course.CourseList;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
...@@ -18,7 +22,13 @@ class AdminTest { ...@@ -18,7 +22,13 @@ class AdminTest {
void setUpTearDown() { void setUpTearDown() {
userList = new UserList(); userList = new UserList();
courseList = new CourseList(); courseList = new CourseList();
testAdmin = new Admin("falseAdmin", "False Admin", userList);
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
testAdmin = new Admin("testAdmin", "Test Admin", userList);
testTa = new TeachingAssistant("testTa", testTa = new TeachingAssistant("testTa",
"Test Teacher", Long.parseLong("123456789"), userList); "Test Teacher", Long.parseLong("123456789"), userList);
testStudent = new Student("testStudent", testStudent = new Student("testStudent",
...@@ -64,4 +74,42 @@ class AdminTest { ...@@ -64,4 +74,42 @@ class AdminTest {
@Test @Test
void getUsername() { void getUsername() {
} }
@AfterEach
void finalTearDown() {
courseList = new CourseList();
userList = new UserList();
// Uncomment here to add a new TA or Admin
// This will add false users, for checking users in the arraylist. (NECESSARY)
new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
new Admin("falseAdmin", "False Admin", userList);
// Add testStudent
new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList);
// Add testTa with a mock calendar and schedule
TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList);
testTa.setSchedule("monday", "Free", "12:00", "17:00");
testTa.setSchedule("tuesday", "Free", "08:00", "11:00");
testTa.setSchedule("tuesday", "Free", "12:00", "15:00");
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Free", "12:00", "17:00");
new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList);