-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectTest.java
More file actions
556 lines (465 loc) · 19 KB
/
ProjectTest.java
File metadata and controls
556 lines (465 loc) · 19 KB
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
/*
* @authour: muteeba jamal <a href="mailto:muteeba.jamal@ucalgary.ca">
* muteeba.jamal@ucalgary.ca</a>
* @authour: shahzill naveed <a href="mailto:shahzill.naveed@ucalgary.ca">
* shahzill.naveed@ucalgary.ca</a>
* @authour: ahsan zia <a href="mailto:ahsan.zia@ucalgary.ca">
* ahsan.zia@ucalgary.ca</a>
* @authour: hridika banik <a href="mailto:hridika.banik@ucalgary.ca">
* hridika.banik@ucalgary.ca</a>
* @version 3.2
* @since 1.0
*/
/* This test class is designed to test a food ordering system
* The tests are all formed keeping in mind the boundary conditions
* that may be provided.
*/
package edu.ucalgary.ensf409;
import org.junit.*;
import static org.junit.Assert.*;
import java.io.*;
import java.util.*;
/* *********** Tests for the Project. *********** */
public class ProjectTest {
String[][] clients = {
{"1", "male" , "45" , "22" , "53" , "32" ,"2154"},
{"2", "female" , "45" , "56" , "53" , "32" ,"1134"},
{"3", "childu" , "45" , "22" , "21" , "62" ,"1834"},
{"4", "childo" , "45" , "22" , "53" , "32" ,"1959"}
};
String[][] clientsOverLoad = {
{"1", "male" , "4500" , "25646" , "53466" , "32" ,"215465"},
{"2", "female" , "45006" , "564654" , "53" , "32" ,"113468"},
{"3", "childu" , "45646" , "2248646" , "21" , "6246846" ,"183445"},
{"4", "childo" , "457898" , "224684" , "53468" , "32" ,"65465"}
};
String[][] clientsBadData = {
{"1", "male" , "-545" , "-22" , "53" , "32" ,"2154"},
{"2", "female" , "45" , "56" , "53" , "-32" ,"1134"},
{"3", "childu" , "-45" , "-522" , "21" , "62" ,"1834"},
{"4", "childo" , "45" , "22" , "53" , "32" ,"1959"}
};
private LinkedList<Food> foods =new LinkedList<Food>();
Food f1 = new Food("24" ,"Tomato Sauce, jar", "0", "80", "10", "10", "120");
Food f2 = new Food("14" ,"Tomato Sauce, jar", "0", "80", "10", "10", "120");
Food f3 = new Food("133" ,"Apple, dozen","0" ,"100", "0", "0", "624");
Food f4 = new Food("132" ,"Apple, dozen","1000" ,"1000", "1000", "1000", "3000");
/* The following methods are designed to test the
* constructors by inputting the correct data
*/
@Test
public void testClientConstructorGoodData() {
Client oneClient = new Client(clients);
assertNotNull("CLient constructor did not create an object when given a valid array of log entries.", oneClient);
}
@Test
public void testInventoryConstructorGoodData() {
foods.add(f1);
foods.add(f2);
foods.add(f3);
Inventory array = new Inventory(foods);
assertNotNull("Inventory constructor did not create an object when given a valid log string.", array);
}
@Test
public void testFoodConstructorGoodData() {
Food food = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");
assertNotNull("Food constructor did not create an object when given a valid log string.", food);
}
@Test
public void testHamperConstructorGoodData() {
Inventory array = new Inventory(foods);
Hamper testing = new Hamper(2 , 3 , 5 , 6);
assertNotNull("Hamper constructor did not create an object when given a valid log string.", testing);
}
@Test
public void testHamperOneConstructorGoodData() {
Inventory array = new Inventory(foods);
Hamper testing = new Hamper(1156 , 756 , 55 , 353, 815);
assertNotNull("Hamper constructor did not create an object when given a valid log string.", testing);
}
@Test
public void testOrderConstructorGoodData() {
Order testing = null;
try {
testing = new Order("people" ,"peopleeeee" , 13);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertNotNull("Order constructor did not create an object when given a valid log string.", testing);
}
/* The following methods are designed to test the
* constructors by inputting the incorrect data
*/
@Test
public void testClientConstructorInvalidData() {
boolean correctException = false;
try{
Client invalidClient = new Client(clientsBadData);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("Client constructor did not throw an IllegalArgumentException when given an invalid Client constructor: ", true, correctException);
}
@Test
public void testFoodConstructorInvalidData() {
boolean correctException = false;
try{
Food invalidFood = new Food("45","Tomato Sauce, jar", "0", "-80", "10", "-10", "120");
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("Food constructor did not throw an IllegalArgumentException when given an invalid Food Constructor: ", true, correctException);
}
@Test
public void testHamperConstructorInvalidData() {
boolean correctException = false;
try{
Hamper invalidHamper = new Hamper(2 , -3 , 5 , -6);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("Hamper constructor did not throw an IllegalArgumentException when given an invalid Hamper constructor: ", true, correctException);
}
@Test
public void testOrderConstructorInvalidData() {
boolean correctException = false;
try{
Order invalidOrder = new Order("SDbjjh", "hiji", -9);
}
catch(IllegalArgumentException e){
correctException = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertEquals("Order constructor did not throw an IllegalArgumentException when given an invalid Order Constructor: ", true, correctException);
}
/* The following methods test the functionality of
* all the setter and getter methods for the
* Client class
*/
@Test
public void testSetWheat() {
Client testing = new Client(clients);
testing.setWheat(1, 56);
int foundUserID = testing.getWheat(1);
int expectedUserID = 56;
assertEquals("Method SetWheat did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetFruitVeggies() {
Client testing = new Client(clients);
testing.setFruitVeggies(1,56);
int foundUserID = testing.getFruitVeggies(1);
int expectedUserID = 56;
assertEquals("Method SetFruitVeggies did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetProtein() {
Client testing = new Client(clients);
testing.setProtein(1,56);
int foundUserID = testing.getProtein(1);
int expectedUserID = 56;
assertEquals("Method testSetProtein did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetOthers() {
Client testing = new Client(clients);
testing.setOther(1,56);
int foundUserID = testing.getOther(1);
int expectedUserID = 56;
assertEquals("Method setOthers did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetCalories() {
Client testing = new Client(clients);
testing.setCalories(1,5658);
int foundUserID = testing.getCalories(1);
int expectedUserID = 5658;
assertEquals("Method setCalories did not return the expected result: ", expectedUserID, foundUserID);
}
/* The following methods test the functionality of
* all the setter and getter methods for the
* Food class
*/
@Test
public void testSetGrainC() {
Food testing = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");;
testing.setGrainC(56);
int foundUserID = testing.getGrainC();
int expectedUserID = 56;
assertEquals("Method setGrainC did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetFruitVegC() {
Food testing = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");;
testing.setFruitVegC(56);
int foundUserID = testing.getFruitVegC();
int expectedUserID = 56;
assertEquals("Method setFruitVegC did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetProteinC() {
Food testing = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");;
testing.setProtenC(56);
int foundUserID = testing.getProteinC();
int expectedUserID = 56;
assertEquals("Method setProteinC did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetOtherC() {
Food testing = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");;
testing.setOtherC(56);
int foundUserID = testing.getOtherC();
int expectedUserID = 56;
assertEquals("Method setOtherC did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetCalorieC() {
Food testing = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");;
testing.setCalorie(56);
int foundUserID = testing.getCalorie();
int expectedUserID = 56;
assertEquals("Method setCalorieC did not return the expected result: ", expectedUserID, foundUserID);
}
/* The following methods test the functionality of
* all the setter and getter methods for the
* Food class by inputting the wrong data and seeing
* if an error is thrown.
*/
@Test
public void testsetCalorieException() {
boolean correctException = false;
try{
Food food = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");
food.setCalorie(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setCalorie did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testsetWheatCException() {
boolean correctException = false;
try{
Food food = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");
food.setGrainC(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setGrainC did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testProteinCException() {
boolean correctException = false;
try{
Food food = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");
food.setProtenC(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setProteinC did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testsetFruitVegCException() {
boolean correctException = false;
try{
Food food = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");
food.setFruitVegC(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setFruitVegC did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testsetOtherCException() {
boolean correctException = false;
try{
Food food = new Food("45","Tomato Sauce, jar", "0", "80", "10", "10", "120");
food.setOtherC(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setOtherC did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
/* The following methods test the functionality of
* all the setter and getter methods for the
* Client class by inputting the wrong data and seeing
* if an error is thrown.
*/
@Test
public void testsetWheatException() {
boolean correctException = false;
try{
Client client = new Client(clients);
client.setWheat(1,-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setWheat did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testsetProteinException() {
boolean correctException = false;
try{
Client client = new Client(clients);
client.setProtein(1,-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setProtein did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testsetFruitVeggiesException() {
boolean correctException = false;
try{
Client client = new Client(clients);
client.setFruitVeggies(1,-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setFruitVeggies did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testsetOthersException() {
boolean correctException = false;
try{
Client client = new Client(clients);
client.setOther(1,-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setOthers did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testsetCaloriesException() {
boolean correctException = false;
try{
Client client = new Client(clients);
client.setCalories(1,-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setCalories did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
/* The following methods test the functionality of
* all the setter and getter methods for the
* Hamper class by inputting the right data.
*/
@Test
public void testSetTWG() {
Inventory array = new Inventory(foods);
Hamper testing = new Hamper(275, 145, 435 ,315, 825);
testing.setTWG(89);
int foundUserID = testing.getTWG();
int expectedUserID = 89;
assertEquals("Method setUserTWG did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetTFV() {
Inventory array = new Inventory(foods);
Hamper testing = new Hamper(275, 145, 435 ,315, 825);
testing.setTFV(89);
int foundUserID = testing.getFV();
int expectedUserID = 89;
assertEquals("Method setUserTFV did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetTP() {
Inventory array = new Inventory(foods);
Hamper testing = new Hamper(275, 145, 435 ,315, 825);
testing.setTP(89);
int foundUserID = testing.getTP();
int expectedUserID = 89;
assertEquals("Method setTP did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetTO() {
Inventory array = new Inventory(foods);
Hamper testing = new Hamper(275, 145, 435 ,315, 825);
testing.setTO(89);
int foundUserID = testing.getTO();
int expectedUserID = 89;
assertEquals("Method setUserTO did not return the expected result: ", expectedUserID, foundUserID);
}
@Test
public void testSetTC() {
Inventory array = new Inventory(foods);
Hamper testing = new Hamper(275, 145, 435 ,315, 825);
testing.setTC(89);
int foundUserID = testing.getTC();
int expectedUserID = 89;
assertEquals("Method setTC did not return the expected result: ", expectedUserID, foundUserID);
}
/* The following methods test the functionality of
* all the setter and getter methods for the
* class by inputting the wrong data and seeing
* if an error is thrown.
*/
@Test
public void testSetTWGException() {
boolean correctException = false;
try{
Inventory array = new Inventory(foods);
Hamper client = new Hamper(2, 1, 4 , 0);
Hamper.setTWG(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setTWG did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testSetTPException() {
boolean correctException = false;
try{
Inventory array = new Inventory(foods);
Hamper client = new Hamper(2, 1, 4 , 0);
Hamper.setTP(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setTP did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testSetTOException() {
boolean correctException = false;
try{
Inventory array = new Inventory(foods);
Hamper client = new Hamper(2, 1, 4 , 0);
Hamper.setTO(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("setTO did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
@Test
public void testSetTCException() {
boolean correctException = false;
try{
Inventory array = new Inventory(foods);
Hamper client = new Hamper(2, 1, 4 , 0);
Hamper.setTC(-1);
}
catch(IllegalArgumentException e){
correctException = true;
}
assertEquals("SetTC did not throw an IllegalArgumentException when given invalid input: ", true, correctException);
}
}