-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataWriterTest.java
203 lines (184 loc) · 8.28 KB
/
DataWriterTest.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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;
public class DataWriterTest {
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();
private ArrayList<User> testUsers = userList.getUsers(); // Constant used for comparison
private ArrayList<Author> testAuthors = userList.getAuthors(); // Constant used for comparison
private ArrayList<Course> testCourses = courseList.getCourses(); // Constant used for comparison
@BeforeEach
public void setup() {
userList.getUsers().clear();
DataWriter.writeUsers(userList.getUsers());
userList.getAuthors().clear();
DataWriter.writeAuthors(userList.getAuthors());
courseList.getCourses().clear();
DataWriter.writeCourses(courseList.getCourses());
}
@AfterEach
public void tearDown() {
userList.getUsers().clear();
DataWriter.writeUsers(userList.getUsers());
userList.getAuthors().clear();
DataWriter.writeAuthors(userList.getAuthors());
courseList.getCourses().clear();
DataWriter.writeCourses(courseList.getCourses());
}
@Test
void testWritingZeroUsers() {
users = DataLoader.loadUsers();
assertEquals(0, users.size());
}
@Test
void testWritingOneUser() {
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();
}
users.add(new User("Daniel", "Chavez","dchavez", "leafblower98", dob, "874-000-3440", "[email protected]"));
DataWriter.writeUsers(users);
assertEquals("dchavez", DataLoader.loadUsers().get(0).getUserName());
}
@Test
void testWritingFiveUsers() {
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();
}
users.add(new User("Daniel", "Chavez","1chavez", "leafblower98", dob, "874-000-3440", "[email protected]"));
users.add(new User("Daniel", "Chavez","2chavez", "leafblower98", dob, "874-000-3440", "[email protected]"));
users.add(new User("Daniel", "Chavez","3chavez", "leafblower98", dob, "874-000-3440", "[email protected]"));
users.add(new User("Daniel", "Chavez","4chavez", "leafblower98", dob, "874-000-3440", "[email protected]"));
users.add(new User("Daniel", "Chavez","5chavez", "leafblower98", dob, "874-000-3440", "[email protected]"));
DataWriter.writeUsers(users);
assertEquals("5chavez", DataLoader.loadUsers().get(4).getUserName());
}
@Test
void testWritingZeroAuthors() {
authors = DataLoader.loadAuthors();
assertEquals(0, authors.size());
}
@Test
void testWritingOneAuthor() {
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();
}
authors.add(new Author("Brian", "McCaster","bmccaster", "89rewolbfael", dob, "980-234-2234", "[email protected]"));
DataWriter.writeAuthors(authors);
assertEquals("bmccaster", DataLoader.loadAuthors().get(0).getUserName());
}
@Test
void testWritingFiveAuthors() {
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();
}
authors.add(new Author("Brian", "McCaster","bmccaster1", "89rewolbfael", dob, "980-234-2234", "[email protected]"));
authors.add(new Author("Brian", "McCaster","bmccaster2", "89rewolbfael", dob, "980-234-2234", "[email protected]"));
authors.add(new Author("Brian", "McCaster","bmccaster3", "89rewolbfael", dob, "980-234-2234", "[email protected]"));
authors.add(new Author("Brian", "McCaster","bmccaster4", "89rewolbfael", dob, "980-234-2234", "[email protected]"));
authors.add(new Author("Brian", "McCaster","bmccaster5", "89rewolbfael", dob, "980-234-2234", "[email protected]"));
DataWriter.writeAuthors(authors);
assertEquals("bmccaster5", DataLoader.loadAuthors().get(4).getUserName());
}
@Test
void testWritingZeroCourses() {
courses = DataLoader.loadCourses();
assertEquals(0, courses.size());
}
@Test
void testWritingOneCourse() {
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();
}
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);
DataWriter.writeCourses(courses);
assertEquals("Course", DataLoader.loadCourses().get(0).getCourseName());
}
@Test
void testWritingFiveCourses() {
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();
}
Author tempAuthor = new Author("Brian", "McCaster","bmccaster", "89rewolbfael", dob, "980-234-2234", "[email protected]");
for(int i = 1; i<6; i++) {
Course tempCourse = new Course("Course"+i, 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);
}
DataWriter.writeCourses(courses);
assertEquals("Course5", DataLoader.loadCourses().get(4).getCourseName());
}
}