-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataLoaderTest.java
451 lines (389 loc) · 16 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class DataLoaderTest {
private UserList userList = UserList.getInstance();
private ArrayList<User> users = userList.getUsers();
private CourseList courseList = CourseList.getInstance();
private ArrayList<Course> courses = courseList.getAllCourses();
private FAQList faqList = FAQList.getInstance();
private ArrayList<FAQ> faqs = faqList.getFAQ();
@BeforeEach
public void setup() {
users.clear();
users.add(new User("Anne","Dennis","[email protected]",new Date(10/02/2023), "adennis2", "catsForLife",AccountType.AUTHOR));
UUID randomID = UUID.fromString("3e8a2a51-4dad-482f-9ca4-0fe615e979b0");
users.add(new User(randomID, "Kim","Nguyen","[email protected]",new Date(10/03/1960), "kNguyen", "foodieForLife",AccountType.AUTHOR));
users.add(new User(null, null, null, new Date(), null, null, AccountType.AUTHOR));
DataWriter.saveUsers();
ArrayList<String> answers = new ArrayList<String>();
answers.add("name");
answers.add("street");
answers.add("price");
answers.add("build time");
ArrayList<String> answers2 = new ArrayList<String>();
answers2.add("print(“Hello World”)");
answers2.add("System.out.println(“Hello World”);");
answers2.add("cout << “Hello World”");
answers2.add("print(“Hello World);");
Question question = new Question("What would be a variable for a Cat class?",answers,0);
Question question2 = new Question("How do you print “Hello World”in python?",answers2,0);
ArrayList<Question> questions = new ArrayList<Question>();
questions.add(question);
ArrayList<Question> questions2 = new ArrayList<Question>();
questions2.add(question2);
Quiz quiz = new Quiz(questions);
Quiz quiz2 = new Quiz(questions2);
Lesson lesson = new Lesson("A class is used when you have an object that has several traits.","When to Use Classes: Variables", quiz);
Lesson lesson2 = new Lesson("Printing in python is when you print to the terminal or console so the user can see. You would use the command print().","Printing", quiz2);
ArrayList<Lesson> lessons = new ArrayList<Lesson>();
lessons.add(lesson);
ArrayList<Lesson> lessons2 = new ArrayList<Lesson>();
lessons2.add(lesson2);
Module module = new Module("Variables", lessons);
Module module2 = new Module("Python Basic", lessons2);
ArrayList<Module> modules = new ArrayList<Module>();
modules.add(module);
ArrayList<Module> modules2 = new ArrayList<Module>();
modules2.add(module2);
courses.add(new Course(UUID.randomUUID(), "Classes for Beginners", "Teaches how to create a class with variables and methods, then describes when to use a class.", "Module 1: Variables, Module 2: Methods, Module: When to Use Classes", Difficulty.MEDIUM, Language.PYTHON, modules));
courses.add(new Course(UUID.fromString("5a118dcd-901e-43c3-b153-c67b2a2448d9"), "Zero to Hero: Python Bootcamp", "Learning Python like a Professional Start from the basics and go all the way to creating your own applications and games!", "Module 1: Python Basic.", Difficulty.EASY, Language.PYTHON, modules2));
courses.add(new Course(UUID.randomUUID(), null, null, null, Difficulty.EASY, Language.GITHUB, new ArrayList<Module>()));
ArrayList<String> answersNull = new ArrayList<String>();
answersNull.add("");
Question questionNull = new Question("",answersNull,0);
ArrayList<Question> questionsNull = new ArrayList<Question>();
questionsNull.add(questionNull);
Quiz quizNull = new Quiz(questionsNull);
Lesson lessonNull = new Lesson("","", quizNull);
ArrayList<Lesson> lessonsNull = new ArrayList<Lesson>();
lessonsNull.add(lessonNull);
Module moduleNull = new Module("", lessonsNull);
ArrayList<Module> modulesNull = new ArrayList<Module>();
modulesNull.add(moduleNull);
courses.add(new Course(UUID.randomUUID(), "", "", "", Difficulty.EASY, Language.PYTHON, modulesNull));
DataWriter.saveCourses();
faqs.add(new FAQ("Would this course be helpful when interviewing with Google?", "Yes, Google likes to see that you understand object-oriented programming."));
faqs.add(new FAQ("How do I create a course on this platform?", "You would need to make an account as a author in order to create courses."));
faqs.add(new FAQ("What languages does this system offer for courses", "We offer python, javaScript, and git."));
faqs.add(new FAQ("",""));
DataWriter.saveFAQs();
}
@AfterEach
public void tearDown() {
UserList.getInstance().getUsers().clear();
DataWriter.saveUsers();
CourseList.getInstance().getAllCourses().clear();
DataWriter.saveCourses();
FAQList.getInstance().getFAQ().clear();
DataWriter.saveFAQs();
}
//test get users size
@Test
void testGetUsersSize() {
users = DataLoader.getUsers();
assertEquals(3, userList.size());
}
//test get users size 0
@Test
void testGetUsersSizeZero() {
UserList.getInstance().getUsers().clear();
DataWriter.saveUsers();
assertEquals(0, userList.size());
}
//test get user id
@Test
void testGetUserID() {
users = DataLoader.getUsers();
UUID randomIDUser2 = UUID.fromString("3e8a2a51-4dad-482f-9ca4-0fe615e979b0");
assertEquals(randomIDUser2, users.get(1).getId());
}
//test get user null id
@Test
void testGetUserIDNull() {
users = DataLoader.getUsers();
assertEquals(null, users.get(2).getId());
}
//test get user valid firstName
@Test
void testGetUserFirstName() {
users = DataLoader.getUsers();
assertEquals("Anne", users.get(0).getFirstName());
}
//test get user null firstName
@Test
void testGetUserFirstNameNull() {
users = DataLoader.getUsers();
assertEquals(null, users.get(2).getFirstName());
}
//test get user valid lastName
@Test
void testGetUserLastName() {
users = DataLoader.getUsers();
assertEquals("Dennis", users.get(0).getLastName());
}
//test get user null lastName
@Test
void testGetUserLastNameNull() {
users = DataLoader.getUsers();
assertEquals(null, users.get(2).getLastName());
}
//test get user valid email
@Test
void testGetUserEmail() {
users = DataLoader.getUsers();
assertEquals("[email protected]", users.get(0).getEmail());
}
//test get user null email
@Test
void testGetUserEmailNull() {
users = DataLoader.getUsers();
assertEquals(null, users.get(2).getEmail());
}
//test get user valid birthday
@Test
void testGetUserBirthday() {
users = DataLoader.getUsers();
assertEquals(new Date(10/02/2023), users.get(0).getBirthday());
}
//test get user null birthday
@Test
void testGetUserBirthdayNull() {
users = DataLoader.getUsers();
assertEquals(null, users.get(2).getBirthday());
}
//test get user wrong format birthday
/*
@Test
void testGetUserBirthdayWrongFormat() {
users = DataLoader.getUsers();
users.add(new User(UUID.fromString("c0bef27c-9eb4-4d16-bd3e-10cf8d9c1e57"), "Bill", "Dennis", "[email protected]", new Date(01/12/2000), "bdennis", "DogLover3498", AccountType.AUTHOR));
assertEquals(new Date(10/02/2023), users.get(2).getEmail());
}*/
//test get user valid username
@Test
void testGetUserUsername() {
users = DataLoader.getUsers();
assertEquals("adennis2", users.get(0).getUsername());
}
//test get user null username
@Test
void testGetUserUsernameNull() {
users = DataLoader.getUsers();
assertEquals(null, users.get(2).getUsername());
}
//test get user valid password
@Test
void testGetUserPassword() {
users = DataLoader.getUsers();
assertEquals("catsForLife", users.get(0).getPassword());
}
//test get user null password
@Test
void testGetUserPasswordNull() {
users = DataLoader.getUsers();
assertEquals(null, users.get(2).getPassword());
}
//test get user valid type
@Test
void testGetUserType() {
users = DataLoader.getUsers();
assertEquals(AccountType.AUTHOR, users.get(0).getType());
}
//test get user null type
//test get user unknown type
@Test
void testGetUserTypeUnknown() {
users = DataLoader.getUsers();
users.add(new User(null, null, null, new Date(), null, null, AccountType.valueOf("")));
assertEquals(AccountType.STUDENT, users.get(3).getType());
}
//test get courses size
@Test
void testGetCoursesSize() {
courses = DataLoader.getCourses();
assertEquals(4, courseList.size());
}
//test get courses size 0
@Test
void testGetCoursesSizeZero() {
CourseList.getInstance().getAllCourses().clear();
DataWriter.saveCourses();
assertEquals(0, courseList.size());
}
@Test
void testGetCourseID() {
courses = DataLoader.getCourses();
assertEquals(UUID.fromString("5a118dcd-901e-43c3-b153-c67b2a2448d9"), courses.get(1).getId());
}
/*
@Test
void testGetCourseIDNull() {
users = DataLoader.getUsers();
assertEquals(null, users.get(2).getId());
}*/
@Test
void testGetCourseDifficulty() {
courses = DataLoader.getCourses();
assertEquals(Difficulty.MEDIUM, courses.get(0).getDifficulty());
}
@Test
void testGetCourseDifficultyUnknown() {
courses = DataLoader.getCourses();
courses.add(new Course(null, null, null, null, Difficulty.valueOf("unknown"), Language.valueOf("unknown"), null));
assertEquals(Difficulty.EASY, courses.get(3).getDifficulty());
}
@Test
void testGetCourseLanguage() {
courses = DataLoader.getCourses();
assertEquals(Language.PYTHON, courses.get(0).getLanguage());
}
@Test
void testGetCourseLanguageUnknown() {
courses = DataLoader.getCourses();
courses.add(new Course(null, null, null, null, Difficulty.valueOf("unknown"), Language.valueOf("unknown"), null));
assertEquals(Language.GITHUB, courses.get(3).getDifficulty());
}
@Test
void testGetCourseName() {
courses = DataLoader.getCourses();
assertEquals("Classes for Beginners", courses.get(0).getTitle());
}
@Test
void testGetCourseNameNull() {
courses = DataLoader.getCourses();
assertEquals(null, courses.get(2).getTitle());
}
@Test
void testGetCourseDescription() {
courses = DataLoader.getCourses();
assertEquals("Teaches how to create a class with variables and methods, then describes when to use a class.", courses.get(0).getDesciption());
}
@Test
void testGetCourseDescriptionNull() {
courses = DataLoader.getCourses();
assertEquals(null, courses.get(2).getDesciption());
}
@Test
void testGetCourseSyllabus() {
courses = DataLoader.getCourses();
assertEquals("Module 1: Variables, Module 2: Methods, Module: When to Use Classes", courses.get(0).getSyllabus());
}
@Test
void testGetCourseSyllabusNull() {
courses = DataLoader.getCourses();
assertEquals(null, courses.get(2).getSyllabus());
}
@Test
void testGetCourseModuletitle() {
courses = DataLoader.getCourses();
assertEquals("Variables", courses.get(0).getModule().get(0).getTitle());
}
@Test
void testGetCourseModuleTitleNull() {
courses = DataLoader.getCourses();
assertEquals("", courses.get(3).getModule().get(0).getTitle());
}
@Test
void testGetCourseModuleLessontitle() {
courses = DataLoader.getCourses();
assertEquals("When to Use Classes: Variables", courses.get(0).getModule().get(0).getLesson().get(0).getTitle());
}
@Test
void testGetCourseModuleLessonTitleNull() {
courses = DataLoader.getCourses();
assertEquals("", courses.get(3).getModule().get(0).getLesson().get(0).getTitle());
}
@Test
void testGetCourseModuleLessonContent() {
courses = DataLoader.getCourses();
assertEquals("A class is used when you have an object that has several traits.", courses.get(0).getModule().get(0).getLesson().get(0).getContent());
}
@Test
void testGetCourseModuleLessonContentNull() {
courses = DataLoader.getCourses();
assertEquals("", courses.get(3).getModule().get(0).getLesson().get(0).getContent());
}
@Test
void testGetCourseModuleLessonQuizQuestionQuestion() {
courses = DataLoader.getCourses();
assertEquals("What would be a variable for a Cat class?", courses.get(0).getModule().get(0).getLesson().get(0).getQuiz().getQuestion().get(0).getQuestion());
}
@Test
void testGetCourseModuleLessonQuizQuestionQuestionNull() {
courses = DataLoader.getCourses();
assertEquals("", courses.get(3).getModule().get(0).getLesson().get(0).getQuiz().getQuestion().get(0).getQuestion());
}
@Test
void testGetCourseModuleLessonQuizQuestionCorrectAns() {
courses = DataLoader.getCourses();
assertEquals(0, courses.get(0).getModule().get(0).getLesson().get(0).getQuiz().getQuestion().get(0).getCorrectAnswer());
}
@Test
void testGetCourseModuleLessonQuizQuestionAnswer() {
courses = DataLoader.getCourses();
assertEquals("street", courses.get(0).getModule().get(0).getLesson().get(0).getQuiz().getQuestion().get(0).getAnswers().get(1));
}
@Test
void testGetCourseModuleLessonQuizQuestionAnswerNull() {
courses = DataLoader.getCourses();
assertEquals("", courses.get(3).getModule().get(0).getLesson().get(0).getQuiz().getQuestion().get(0).getAnswers().get(0));
}
@Test
void testGetCourseModulesSize() {
courses = DataLoader.getCourses();
assertEquals(1, courseList.getAllCourses().get(0).getModule().size());
}
@Test
void testGetCourseModuleLessonsSize() {
courses = DataLoader.getCourses();
assertEquals(1, courseList.getAllCourses().get(0).getModule().get(0).getLesson().size());
}
@Test
void testGetCourseModuleLessonQuizQuestionsSize() {
courses = DataLoader.getCourses();
assertEquals(1, courseList.getAllCourses().get(0).getModule().get(0).getLesson().get(0).getQuiz().getQuestion().size());
}
@Test
void testGetCourseModuleLessonQuizQuestionAnswersSize() {
courses = DataLoader.getCourses();
assertEquals(4, courseList.getAllCourses().get(0).getModule().get(0).getLesson().get(0).getQuiz().getQuestion().get(0).getAnswers().size());
}
//test get FAQs size
@Test
void testGetFAQsSize() {
faqs = DataLoader.getFAQs();
assertEquals(4, faqList.size());
}
//test get FAQs size 0
@Test
void testGetFAQsSizeZero() {
FAQList.getInstance().getFAQ().clear();
DataWriter.saveUsers();
assertEquals(0, faqList.size());
}
@Test
void testGetFAQQuestion() {
faqs = DataLoader.getFAQs();
assertEquals("Would this course be helpful when interviewing with Google?", faqs.get(0).getQuestion());
}
@Test
void testGetFAQQuestionNull() {
faqs = DataLoader.getFAQs();
assertEquals("", faqs.get(3).getQuestion());
}
@Test
void testGetFAQAnswer() {
faqs = DataLoader.getFAQs();
assertEquals("Yes, Google likes to see that you understand object-oriented programming.", faqs.get(0).getAnswers().get(0));
}
@Test
void testGetFAQAnswerNull() {
faqs = DataLoader.getFAQs();
assertEquals("", faqs.get(3).getAnswers().get(0));
}
}