-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataWriterTest.java
244 lines (206 loc) · 9.12 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
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
//zak elguindi
import static org.junit.jupiter.api.Assertions.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class DataWriterTest {
private ArrayList<Camper> campers = DataLoader.loadCampers();
private ArrayList<Counselor> counselors = DataLoader.loadCounselors();
private ArrayList<User> users = DataLoader.loadUsers();
private ArrayList<Director> directors = DataLoader.loadDirectors();
private ArrayList<Camp> camps = DataLoader.loadCamps();
@BeforeEach
public void setup() {
campers.clear();
DataWriter.saveCampers();
counselors.clear();
DataWriter.saveCounselors();
users.clear();
DataWriter.saveUsers();
}
@Test
void testWritingZeroCampers() {
assertEquals(0, campers.size());
}
@Test
void testWritingOneCamper() {
ArrayList<Contact> contacts = new ArrayList<Contact>();
contacts.add(new Contact("mary", "green", "145-295-6639", "[email protected]", "mother"));
ArrayList<Medication> medications = new ArrayList<Medication>();
medications.add(new Medication("epipen", "one shot", "when reaction occurs"));
ArrayList<String> allergies = new ArrayList<String>();
allergies.add(new String("peanut allergy"));
campers.add(new Camper("james", "green", "44 thorndale drive", convertToDate("8/11/2014"), Sex.MALE,
medications, allergies, contacts,
new Contact("Dr. ", "Smith", "202-433-5935", "[email protected]", "doctor")));
assertEquals("james", campers.get(0).getFirstName());
}
@Test
void testWritingThreeCampers() {
ArrayList<Contact> contacts = new ArrayList<Contact>();
contacts.add(new Contact("mary", "green", "145-295-6639", "[email protected]", "mother"));
ArrayList<Medication> medications = new ArrayList<Medication>();
medications.add(new Medication("epipen", "one shot", "when reaction occurs"));
ArrayList<String> allergies = new ArrayList<String>();
allergies.add(new String("peanut allergy"));
Contact doctor = new Contact("Dr. ", "Smith", "202-433-5935", "[email protected]", "doctor");
campers.add(new Camper("james", "green", "44 thorndale drive", convertToDate("8/11/2014"), Sex.MALE,
medications, allergies, contacts,
doctor));
contacts.remove(0);
medications.remove(0);
allergies.remove(0);
contacts.add(new Contact("Aaron", "Rodgers", "640-629-6406", "[email protected]", "father"));
allergies.add("none");
campers.add(new Camper("Don", "Rodgers", "1024 Packers Drive", convertToDate("04/24/2014"), Sex.MALE,
medications, allergies, contacts, doctor));
contacts.remove(0);
allergies.remove(0);
contacts.add(new Contact("Tom", "Brady", "104-777-2053", "[email protected]", "father"));
allergies.add("pineapples");
medications.add(new Medication("pineapple medicine", "100 mg", "when allergy occurs"));
campers.add(new Camper("Tom ", "Brady Jr.", "12 Blue Drive", convertToDate("7/8/2014"), Sex.MALE, medications,
allergies, contacts, doctor));
assertEquals("12 Blue Drive", campers.get(2).getHomeAddress());
}
@Test
void testWritingCamperNull() {
campers.add(new Camper(null, null, null, null, null, null, null, null, null));
assertEquals(null, campers.get(0).getAllergies());
}
@Test
void testWritingCamperEmpty() {
campers.add(new Camper("", "", "", null, null, null, null, null, null));
assertEquals("", campers.get(0).getFirstName());
}
// counselors
@Test
void writeZeroCounselor() {
counselors.clear();
assertEquals(0, counselors.size());
}
@Test
void writeOneCounselor() {
Contact doctor = new Contact("Dr. ", "Smith", "202-433-5935", "[email protected]", "doctor");
ArrayList<Contact> contacts = new ArrayList<Contact>();
contacts.add(new Contact("kathryn", "france", "400-295-6639", "[email protected]", "mother"));
counselors.add(new Counselor("timothy", "france", "103-400-5380", "[email protected]", "30 benson lane",
convertToDate("12/30/2005"), contacts, doctor,
new LoginInfo("tim", "france")));
assertEquals("tim", counselors.get(0).getUserLogin().getUserName());
}
@Test
void writeThreeCounselors() {
Contact doctor = new Contact("Dr. ", "Smith", "202-433-5935", "[email protected]", "doctor");
ArrayList<Contact> contacts = new ArrayList<Contact>();
contacts.add(new Contact("kathryn", "france", "400-295-6639", "[email protected]", "mother"));
counselors.add(new Counselor("timothy", "france", "103-400-5380", "[email protected]", "30 benson lane",
convertToDate("12/30/2005"), contacts, doctor,
new LoginInfo("tim", "france")));
contacts.remove(0);
contacts.add(new Contact("Josh", "Hughes", "125-255-5830", "[email protected]", "father"));
counselors.add(new Counselor("Jason", "Hughes", "140-266-3590", "[email protected]", "130 prescott drive",
convertToDate("4/13/2005"), contacts, doctor,
new LoginInfo("jason", "hughes")));
contacts.remove(0);
contacts.add(new Contact("Bryce", "Young", "610-253-2005", "[email protected]", "father"));
counselors.add(new Counselor("Ashely", "Young", "610-255-3694", "[email protected]", "180 prescott drive",
convertToDate("05/16/2006"), contacts, doctor,
new LoginInfo("ashley", "young")));
assertEquals("130 prescott drive", counselors.get(1).getHomeAddress());
}
@Test
void writeNullCounselor() {
counselors.add(new Counselor(null, null, null, null, null, null, null, null, null));
assertEquals(null, counselors.get(0).getDateOfBirth());
}
@Test
void writeEmptyCounselor() {
counselors.add(new Counselor("", "", "", "", "", null, null, null, null));
assertEquals("", counselors.get(0).getPhoneNumber());
}
@Test
void testWritingZeroUsers() {
users = DataLoader.loadUsers();
assertEquals(0, users.size());
}
@Test
void writeOneUser() {
users.add(new User("LeBron", "James", convertToDate("08/31/1980"), "16 Calcium Circle",
new LoginInfo("lebron", "james"), campers));
assertEquals("lebron", users.get(0).getUserLogin().getUserName());
}
@Test
void writeThreeUsers() {
users.add(new User("LeBron", "James", convertToDate("08/31/1980"), "16 Calcium Circle",
new LoginInfo("lebron", "james"), campers));
users.add(new User("Michael", "Jordan", convertToDate("12/14/1970"), "23 Bulls Drive",
new LoginInfo("michael", "jordan"), campers));
users.add(new User("Kobe", "Bryant", convertToDate("08/23/1975"), "88 Lake Court",
new LoginInfo("kobe", "Bryant"), campers));
assertEquals("Bryant", users.get(2).getLastName());
}
@Test
void writeNullUser() {
users.add(new User(null, null, null, null, null, null));
assertEquals(null, users.get(0).getCampers());
}
@Test
void writeEmptyUser() {
users.add(new User("", "", null, "", null, null));
assertEquals("", users.get(0).getLastName());
}
// directors
@Test
void writeZeroDirector() {
directors.clear();
assertEquals(0, directors.size());
}
@Test
void editOneDirector() {
directors.get(0).setEmail("[email protected]");
assertEquals("[email protected]", directors.get(0).getEmail());
}
@Test
void writeNullDirector() {
directors.add(new Director(null, null, null, null, null, null, null));
assertEquals(null, directors.get(1).getCamps());
}
@Test
void testEmptyDirector() {
directors.add(new Director("", "", convertToDate(""), "", "", null, null));
assertEquals("", directors.get(1).getDateOfBirth());
}
// camos
@Test
void writeZeroCamps() {
camps.clear();
assertEquals(0, camps.size());
}
@Test
void editOneCamp() {
camps.get(0).getActivitiesArrayList().get(0).setLocation("blank location");
assertEquals("blank location", camps.get(0).getActivitiesArrayList().get(0).getLocation());
}
@Test
void writeNullCamp() {
camps.add(new Camp(null, null, 0, 0, null));
assertEquals(null, camps.get(1).getActivitiesArrayList());
}
@Test
void writeEmptyCamp() {
camps.add(new Camp("", "", 0, 0, null));
assertEquals("", camps.get(1).getName());
}
public static Date convertToDate(String date) {
try {
return new SimpleDateFormat("MM/dd/yyyy").parse(date);
} catch (java.text.ParseException e) {
System.out.println("Sorry " + date + " is not parsable");
return null;
}
}
}