-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataLoaderTest.java
151 lines (125 loc) · 4.52 KB
/
DataLoaderTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import static org.junit.jupiter.api.Assertions.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.UUID;
import java.util.ArrayList;
/**
* Jordan's very cool DataLoader Tester
*/
public class DataLoaderTest {
private UserList userList = UserList.getInstance();
private CourseList courseList = CourseList.getInstance();
private ArrayList<User> users = userList.getUsers();
private ArrayList<Author> authors = userList.getAuthors();
private ArrayList<Course> courses = courseList.getCourses();
@BeforeEach
public void setup() {
users.clear();
authors.clear();
courses.clear();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
String dateOfBirth = "3/13/2003";
Date dob = new Date();
try {
dob = dateFormat.parse(dateOfBirth);
} catch (Exception e) {
e.printStackTrace();
}
User tempUser = new User("Daniel", "Chavez","dchavez", "leafblower98", dob, "874-000-3440", "[email protected]");
Author tempAuthor = new Author("Brian", "McCaster","bmccaster", "89rewolbfael", dob, "980-234-2234", "[email protected]");
Course tempCourse = new Course("Course", tempAuthor);
Module tempModule = new Module("Module");
Lesson tempLesson = new Lesson("Lesson");
tempLesson.setLessonContent("Content");
Comment tempComment = new Comment("dchavez", "comment");
tempComment.reply(new Comment("bmccaster", "reply"));
tempLesson.addComment(tempComment);
tempModule.addLesson(tempLesson);
Quiz tempQuiz = new Quiz();
Question tempQuestion = new Question("Question?");
tempQuestion.addAnswer("Answer1");
tempQuestion.addAnswer("Answer2");
tempQuestion.addAnswer("Answer3");
tempQuestion.setCorrectAnswer(2);
tempQuiz.addQuestion(tempQuestion);
tempModule.setQuiz(tempQuiz);
tempCourse.addModule(tempModule);
courses.add(tempCourse);
ArrayList<CourseProgress> tempCourseProgress = new ArrayList<CourseProgress>();
tempCourseProgress.add(new CourseProgress(tempCourse));
tempUser.setCourseProgress(tempCourseProgress);
users.add(tempUser);
tempAuthor.setCourseProgress(tempCourseProgress);
authors.add(tempAuthor);
DataWriter.writeCourses(courses);
DataWriter.writeUsers(users);
DataWriter.writeAuthors(authors);
}
@AfterEach
public void tearDown() {
users.clear();
DataWriter.writeUsers(users);
authors.clear();
DataWriter.writeAuthors(authors);
courses.clear();
DataWriter.writeCourses(courses);
}
@Test
void testGetUsersSize() {
assertEquals(1, DataLoader.loadUsers().size());
}
@Test
void testGetAuthorsSize() {
assertEquals(1, DataLoader.loadAuthors().size());
}
@Test
void testGetCoursesSize() {
assertEquals(1, DataLoader.loadCourses().size());
}
@Test
void testGetUsersSizeZero() {
users.clear();
DataWriter.writeUsers(users);
assertEquals(0, DataLoader.loadUsers().size());
}
@Test
void testGetAuthorsSizeZero() {
authors.clear();
DataWriter.writeAuthors(authors);
assertEquals(0, DataLoader.loadAuthors().size());
}
@Test
void testGetCoursesSizeZero() {
courses.clear();
DataWriter.writeCourses(courses);
assertEquals(0, DataLoader.loadCourses().size());
}
@Test
void testUserLoad() {
assertEquals("dchavez", DataLoader.loadUsers().get(0).getUserName());
}
@Test
void testAuthorLoad() {
assertEquals("bmccaster", DataLoader.loadAuthors().get(0).getUserName());
}
@Test
void testCourseLoad() {
assertEquals("Course", DataLoader.loadCourses().get(0).getCourseName());
}
@Test
void testUserCourseProgress() {
userList.readUsersJSON();
assertEquals("Course", DataLoader.loadUsersCourseProgress(userList).get(0).getCourseProgress().get(0).getCourse().getCourseName());
}
@Test
void testAuthorLoadCourseProgress() {
userList.readAuthorsJson();
assertEquals("Course", DataLoader.loadAuthorsCourseProgress(userList).get(0).getCourseProgress().get(0).getCourse().getCourseName());
}
}