-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataWriterTester.java
116 lines (88 loc) · 3.32 KB
/
DataWriterTester.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
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import classes.*;
public class DataWriterTester {
private UserList userList = UserList.getInstanceUserList();
private ArrayList<User> users = userList.getUsers();
private CourseList courseList = CourseList.getInstanceCourseList();
private ArrayList<Course> courses = courseList.getCourses();
@BeforeEach
public void setup(){
UserList.getInstanceUserList().getUsers().clear();
DataWriter.saveUsers();
CourseList.getInstanceCourseList().getCourses().clear();
DataWriter.saveCourses();
}
@AfterEach
public void tearDown(){
UserList.getInstanceUserList().getUsers().clear();
DataWriter.saveUsers();
CourseList.getInstanceCourseList().getCourses().clear();
DataWriter.saveCourses();
}
@Test
void testWritingEmptyUsers(){
users = DataLoader.getUsers();
assertEquals(0, users.size());
}
@Test
void testWritingEmptyCourses(){
courses = DataLoader.getCourses();
assertEquals(0, courses.size());
}
@Test
void testWritingOneStudent(){
users.add(new Student("bob","jon","eamil","userName","password"));
DataWriter.saveUsers();
assertEquals("bob", DataLoader.getUsers().get(0).getFirstName());
}
@Test
void testWritingOneAuthor(){
users.add(new Author("jon","long","eamil","userName","password"));
DataWriter.saveUsers();
assertEquals("jon", DataLoader.getUsers().get(0).getFirstName());
}
@Test
void testWritingOneCourse(){
courses.add(new Course("testcourse", "test", null, null, null));
DataWriter.saveCourses();
assertEquals("testcourse", DataLoader.getCourses().get(0).getTitle());
}
@Test
void testWriting3Students(){
users.add(new Student("bob","jon","eamil","userName","password"));
users.add(new Student("hobs","tokin","eamil","userName","password"));
users.add(new Student("andrew","longson","[email protected]","userName","password"));
DataWriter.saveUsers();
assertEquals("andrew", DataLoader.getUsers().get(2).getFirstName());
}
@Test
void testWriting3Author(){
users.add(new Author("jack","cokistock","eamil","userName","password"));
users.add(new Author("mac","liken","eamil","userName","password"));
users.add(new Author("thomas","longson","[email protected]","userName","password"));
DataWriter.saveUsers();
assertEquals("thomas", DataLoader.getUsers().get(2).getFirstName());
}
@Test
void testWritingNullAuthor(){
users.add(new Author(null,null,null,null,null));
DataWriter.saveUsers();
assertEquals(null, DataLoader.getUsers().get(0).getFirstName());
}
@Test
void testWritingNullStudent(){
users.add(new Student(null,null,null,null,null));
DataWriter.saveUsers();
assertEquals(null, DataLoader.getUsers());
}
@Test
void testWritingNUllCourse(){
courses.add(new Course(null, null, null, null, null));
DataWriter.saveCourses();
assertEquals(null, DataLoader.getCourses());
}
}