-
Notifications
You must be signed in to change notification settings - Fork 4
/
TestCase.java
1127 lines (828 loc) · 38.5 KB
/
TestCase.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
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import org.junit.Test;
import javax.swing.*;
import java.util.ArrayList;
import java.util.stream.IntStream;
import static org.junit.Assert.*;
// Test cases for each of the functions used, including the BankAutomated functions and setters and getters.
public class TestCase {
CA dummy;
/* Test 0
* Test case for saving and loading from file
*
*/
@Test
public void saveloadTest(){
BankAutomated BA = new BankAutomated(false);
BA.createAccountTest("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1", "01/01/2027", "555");
// Save to file
BA.logout();
// Load from file
BA = new BankAutomated();
// Test 1
// Check if the account is loaded correctly, correct amount is 0
assertEquals(BA.customerAccounts.size(), 1);
// Test 2
// Check if the account is loaded correctly, correct amount is 0
assertNotEquals(BA.customerAccounts.size(), 2);
BankAutomated BA_test_two = new BankAutomated(false);
int batchSize = 1000;
// Split the workload into 1000 threads, race condition handled by hash map inside createAccount
IntStream.range(0, 1000)
// Each thread work simultaneously
.parallel()
// Each thread do:
.forEach(batch -> {
// start and end for each batch
int start = batch * batchSize;
int end = start + batchSize;
// Do work:
for (int i = start; i < end; i++) {
String email = i + "@gmail.com";
BA_test_two.createAccountTest("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", email, "Hello@World1", "01/01/2027", "555");
}
});
// Save to file
BA_test_two.logout();
// Load from file
BA = new BankAutomated();
// Test 3
// Check if the account is loaded correctly, correct amount is 0
assertEquals(BA.customerAccounts.size(), 1_000_000);
JOptionPane.showMessageDialog(null, "Test cases passed", "Save/Load test", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 1
* Stress test for createAccount and login
*/
@Test
public void stressTest() {
BankAutomated BA = new BankAutomated(false);
long startTime = System.currentTimeMillis();
// Batch size is the amount of work done by each thread
int batchSize = 1000;
// Split the workload into 1000 threads, race condition handled by hash map inside createAccount
IntStream.range(0, 1000)
// Each thread work simultaneously
.parallel()
// Each thread do:
.forEach(batch -> {
// start and end for each batch
int start = batch * batchSize;
int end = start + batchSize;
// Do work:
for (int i = start; i < end; i++) {
String email = i + "@gmail.com";
BA.createAccountTest("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", email, "Hello@World1", "01/01/2027", "555");
}
});
long endTime = System.currentTimeMillis();
double timePassedSeconds = (endTime - startTime);
System.out.println("One million accounts created in " + timePassedSeconds + " milliseconds");
assert timePassedSeconds <= 2000; // Normal loop is 7-9 seconds, this will take 0.5
startTime = System.currentTimeMillis();
dummy = BA.loginAccount("[email protected]", "Hello@World1");
assertNotEquals(dummy, null);
endTime = System.currentTimeMillis();
//noinspection IntegerDivisionInFloatingPointContext
timePassedSeconds = (endTime - startTime)/1000;
System.out.println("Login time: " + timePassedSeconds + " seconds");
assert timePassedSeconds <= 0.1; // Memory Access should be instant
JOptionPane.showMessageDialog(null, "Test cases passed", "Stress test", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 2
* Test case for the createAccount method
*
*/
@Test
public void testRegister() {
BankAutomated BA = new BankAutomated(false);
long startTime = System.currentTimeMillis();
// Test case 1: Valid account
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
assertNotEquals(dummy, null);
// Test case 2: Invalid email
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Female", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
assertNull(dummy);
// Test case 3: Invalid password
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Other", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
assertNull(dummy);
// Test case 4: There should be only one account in the system
assert(BA.customerAccounts.size() == 1);
long endTime = System.currentTimeMillis();
long timePassedSeconds = (endTime - startTime)/1000;
System.out.println("Register time: " + timePassedSeconds + " seconds");
JOptionPane.showMessageDialog(null, "Test cases passed", "testRegister", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 3
* Test case for the loginAccount method
*
*/
@Test
public void testLogin() {
BankAutomated BA = new BankAutomated(false);
long startTime = System.currentTimeMillis();
// Test case 1: Valid account
BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Female", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
dummy = BA.loginAccount("[email protected]", "Hello@World1");
assertNotEquals(dummy, null);
// Test case 2: Invalid email
dummy = BA.loginAccount("[email protected]", "password");
assertNull(dummy);
// Test case 3: Invalid password
dummy = BA.loginAccount("[email protected]", "fc");
assertNull(dummy);
long endTime = System.currentTimeMillis();
long timePassedSeconds = (endTime - startTime)/1000;
System.out.println("Login time: " + timePassedSeconds + " seconds");
JOptionPane.showMessageDialog(null, "Test cases passed", "testLogin", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 4
* Test case for the deposit method
*
*/
@Test
public void testTransferFunds(){
BankAutomated BA = new BankAutomated(false);
long startTime = System.currentTimeMillis();
// Create a customer
CA cust = BA.createAccount("Jane", "Doe", "647-123-4567", "123 Example St.", "Female",
"01/01/2000", "[email protected]", "Password123@", "4417123456789113",
"01/01/2030", "123");
// Test 1
cust.setChequing(10000.0);
cust.setSavings(5000.0);
// Transfer funds add a Transaction object to both Chequing and Savings
BA.transferFunds(5000.0, "Chequing", cust);
assert(cust.getChequing() == 5000.0);
assert(cust.getSavings() == 10000.0);
// Check if the transaction was added to the history
assertEquals(cust.getSavingsHist().size(), 1);
Transaction temp = cust.getSavingsHist().get(0);
int amount = (int) (temp.getAmount() * 1);
// Check if the transaction amount is correct
assertEquals(amount, 5000);
// Check if the transaction was added to the history
assertEquals(cust.getChequingHist().size(), 1);
// Test 2
cust.setChequing(10000.0);
cust.setSavings(5000.0);
BA.transferFunds(5000.0, "Savings", cust);
// Check if the transaction amount is correct
assert(cust.getChequing() == 15000);
assert(cust.getSavings() == 0);
// Check if the transaction was added to the history
assertEquals(cust.getSavingsHist().size(), 2);
temp = cust.getChequingHist().get(0);
amount = (int) (temp.getAmount() * 1);
// Check if the transaction amount is correct
assertEquals(amount, 5000);
assertEquals(cust.getChequingHist().size(), 2);
// Test 3
cust.setChequing(10000.0);
cust.setSavings(5000.0);
// Ensure correct error value is return if there are insufficient funds
assert(BA.transferFunds(5001, "Savings", cust) == 1);
assert(cust.getChequing() == 10000);
assert(cust.getSavings() == 5000);
// Check if the transaction was added to the history
assertEquals(cust.getSavingsHist().size(), 2);
assertEquals(cust.getChequingHist().size(), 2);
// Test 4
cust.setChequing(10000.0);
cust.setSavings(5000.0);
// Ensure correct error value is return if there are insufficient funds
assert(BA.transferFunds(10001, "Chequing", cust) == 1);
assert(cust.getChequing() == 10000);
assert(cust.getSavings() == 5000);
// Check if the transaction was added to the history
assertEquals(cust.getSavingsHist().size(), 2);
assertEquals(cust.getChequingHist().size(), 2);
long endTime = System.currentTimeMillis();
long timePassedSeconds = (endTime - startTime)/1000;
System.out.println("Transfer Funds time: " + timePassedSeconds + " seconds");
JOptionPane.showMessageDialog(null, "Test cases passed", "testTransferFunds", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 5
* Test case for the deposit method
*
*/
@Test
public void testETransfer() {
BankAutomated BA = new BankAutomated(false);
long startTime = System.currentTimeMillis();
// Create a customer
CA jane = BA.createAccountTest("Jane", "Doe", "647-123-4567", "123 Example St.", "Female",
"01/01/2000", "[email protected]", "Password123@",
"01/01/2030", "123");
// Create a customer
CA john = BA.createAccountTest("John", "Doe", "647-987-6543", "321 Example St.", "Male",
"01/01/2000", "[email protected]", "Password123@",
"01/01/2030", "123");
john.setChequing(10000);
jane.setChequing(10000);
// John to Jane
assertEquals(BA.etransfer(999, "[email protected]", john, "Chequing"), 0);
// Check if the transaction amount is correct
assert(john.getChequing() == 10000 - 999);
assert(jane.getChequing() == 10000 + 999);
// Check if the transaction was added to the history
assertEquals(john.getChequingHist().size(), 1);
assertEquals(jane.getChequingHist().size(), 1);
john.setChequing(10000);
jane.setChequing(10000);
// Jane to John
assertEquals(BA.etransfer(999, "[email protected]", jane, "Chequing"), 0);
// Check if the transaction amount is correct
assert(john.getChequing() == 10000 + 999);
assert(jane.getChequing() == 10000 - 999);
// Check if the transaction was added to the history
assertEquals(john.getChequingHist().size(), 2);
assertEquals(jane.getChequingHist().size(), 2);
// Test 1
john.setChequing(10000);
jane.setChequing(10000);
// Amount > limit so no Transfer
assertEquals(BA.etransfer(5000, "[email protected]", john, "Chequing"), 4);
// Check if the transaction amount is correct
assert(john.getChequing() == 10000);
assert(jane.getChequing() == 10000);
// Test 2
john.setChequing(10000);
jane.setChequing(10000);
// Amount > limit so no Transfer
assertEquals(BA.etransfer(5000, "[email protected]", jane, "Chequing"), 4);
assert(jane.getChequing() == 10000);
assert(john.getChequing() == 10000);
// Error code tests
john.setChequing(10000);
jane.setChequing(10000);
// Invalid Email address (returns code 1)
assertEquals(BA.etransfer(500, "johnDoe", jane, "Chequing"), 1);
assert(john.getChequing() == 10000);
assert(jane.getChequing() == 10000);
// Transfer amount above limit, returns error code 4
assertEquals(BA.etransfer(10001, "[email protected]", jane, "Chequing"), 4);
assert(john.getChequing() == 10000);
assert(jane.getChequing() == 10000);
// Email not found (returns code 3) and does an external transaction
assertEquals(BA.etransfer(500, "[email protected]", jane, "Chequing"), 3);
assert(john.getChequing() == 10000);
assert(jane.getChequing() == 9500);
long endTime = System.currentTimeMillis();
long timePassedSeconds = (endTime - startTime)/1000;
System.out.println("Transfer Funds time: " + timePassedSeconds + " seconds");
JOptionPane.showMessageDialog(null, "Test cases passed", "testETransferFunds", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 6
* Test case for the deposit method
*
*/
@Test
public void testBankTransfer()
{
BankAutomated BA = new BankAutomated(false);
long startTime = System.currentTimeMillis();
// Create a customer
CA jane = BA.createAccountTest("Jane", "Doe", "647-123-4567", "123 Example St.", "Female",
"01/01/2000", "[email protected]", "Password123@",
"01/01/2030", "123");
// Create a customer
CA john = BA.createAccountTest("John", "Doe", "647-987-6543", "321 Example St.", "Male",
"01/01/2000", "[email protected]", "Password123@",
"01/01/2030", "123");
jane.setBankNumber("12345");
john.setBankNumber("54321");
// Test 1
john.setChequing(10000);
jane.setChequing(10000);
// Check if transfer is successful
assertEquals(BA.bankTransfer(5000, "12345", john, "Chequing"), 0);
// Check if the transaction amount is correct
assert(john.getChequing() == 5000);
assert(jane.getChequing() == 15000);
// Check if the transaction was added to the history
assertEquals(john.getChequingHist().size(), 1);
assertEquals(jane.getChequingHist().size(), 1);
// Test 2
john.setChequing(10000);
jane.setChequing(10000);
// Check if transfer is successful
assertEquals(BA.bankTransfer(5000, "54321", jane, "Chequing"), 0);
// Check if the transaction amount is correct
assert(jane.getChequing() == 5000);
assert(john.getChequing() == 15000);
// Check if the transaction was added to the history
assertEquals(john.getChequingHist().size(), 2);
assertEquals(jane.getChequingHist().size(), 2);
// Error code tests
john.setChequing(10000);
jane.setChequing(10000);
// Invalid bank number address (returns code 1)
assertEquals(BA.bankTransfer(500, "123456789", jane, "Chequing"), 1);
assert(john.getChequing() == 10000);
assert(jane.getChequing() == 10000);
// Insufficient funds (returns code 2)
assertEquals(BA.bankTransfer(10001, "54321", jane, "Chequing"), 2);
assert(john.getChequing() == 10000);
assert(jane.getChequing() == 10000);
// Email not found (returns code 3), and transfers money to external account
assertEquals(BA.bankTransfer(500, "98765", jane, "Chequing"), 3);
assert(john.getChequing() == 10000);
assert(jane.getChequing() == 9500);
long endTime = System.currentTimeMillis();
long timePassedSeconds = (endTime - startTime)/1000;
System.out.println("Transfer Funds time: " + timePassedSeconds + " seconds");
JOptionPane.showMessageDialog(null, "Test cases passed", "testBankTransferFunds", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 7
* Test case for card expiry
*
*/
@Test
public void testCardExpiry() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
// Test 1
// Check if the card expiry is valid
assertTrue(BA.validCardExpiry(dummy.getCardExpiry()));
dummy.setCardExpiry("01/12/2021");
// Test 2
// Check if the card expiry is invalid
assert(!BA.validCardExpiry(dummy.getCardExpiry()));
JOptionPane.showMessageDialog(null, "Test cases passed", "testCardExpiry", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 8
* Test case for bank number
*
*/
@Test
public void testBankNumber() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
dummy.setBankNumber("12345");
// Test 1
// Check if the bank number is being set
assert(dummy.getBankNumber().equals("12345"));
dummy.setBankNumber("98765");
// Test 2
// Check if the bank number is being set
assert(dummy.getBankNumber().equals("98765"));
// Test 3
// Check if the bank number is valid
assertTrue(BA.validBankNumber("12345"));
// Test 4
// Check if the bank number is invalid
assertFalse(BA.validBankNumber("123456"));
JOptionPane.showMessageDialog(null, "Test cases passed", "testBankNumber", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 9
* Test case for CVV
*
*/
@Test
public void testCVV() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
// Test 1
// Check if the CVV is being set
assert(dummy.getCvv().equals("555"));
dummy.setCvv("787");
// Test 2
// Check if the CVV is being set
assert(dummy.getCvv().equals("787"));
// Test 3
// Check if the CVV is invalid
assertFalse(BA.validCVV("123456"));
// Test 4
// Check if the CVV is valid
assertTrue(BA.validCVV("126"));
JOptionPane.showMessageDialog(null, "Test cases passed", "testCVV", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 10
* Test case for password
*
*/
@Test
public void testPassword() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
// Test 1
// Check if the password is being set
assert(dummy.getPassword().equals("Hello@World1"));
dummy.setPassword("v3RySaf3paSsW0rd");
// Test 2
// Check if the password is being set
assert(dummy.getPassword().equals("v3RySaf3paSsW0rd"));
// Test 3
// Check if the password is valid
assertTrue(BA.validPassword("Hello123!@#"));
// Test 4
// Check if the password is invalid
assertFalse(BA.validPassword("hello123!@#"));
JOptionPane.showMessageDialog(null, "Test cases passed", "testPassword", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 11
* Test case for date of birth
*
*/
@Test
public void testDoB() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
// Test 1
// Check if the DoB is being set
assert(dummy.getDob().equals("01/01/1990"));
dummy.setDob("09/12/2003");
// Test 2
// Check if the DoB is being set
assert(dummy.getDob().equals("09/12/2003"));
// Test 3
// Check if the DoB is invalid
assertTrue(BA.validDOB("09", "01", "2003"));
// Test 4
// Check if the DoB is valid
assertFalse(BA.validDOB("09", "01", "2013"));
JOptionPane.showMessageDialog(null, "Test cases passed", "testDOB", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 12
* Test case for gender
*
*/
@Test
public void testGender() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
// Test 1
// Test if gender is set
assert(dummy.getGender().equals("Male"));
dummy.setGender("Female");
// Test 2
// Test if gender is set
assert(dummy.getGender().equals("Female"));
JOptionPane.showMessageDialog(null, "Test cases passed", "testGender", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 13
* Test case for address
*
*/
@Test
public void testAddress() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
// Test 1
// Check if the address is being set
assert(dummy.getAddress().equals("test street"));
dummy.setAddress("5 CS Road");
// Test 2
// Check if the address is being set
assert(dummy.getAddress().equals("5 CS Road"));
JOptionPane.showMessageDialog(null, "Test cases passed", "testAddress", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 14
* Test case for card number
*
*/
@Test
public void testCardNum() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
// Test 1
// Check if the card number is being set
assert(dummy.getCardNum().equals("4417123456789113"));
dummy.setCardNum("552823455789113");
// Test 2
// Check if the card number is being set
assert(dummy.getCardNum().equals("552823455789113"));
// Test 3
// Check if the card number is valid
assertTrue(BA.validCard("4417123456789113"));
// Test 4
// Check if the card number is invalid
assertFalse(BA.validCard("552823455789113"));
JOptionPane.showMessageDialog(null, "Test cases passed", "testCardNum", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 15
* Test case for chequing set
*
*/
@Test
public void testChequing() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
dummy.setChequing(4545.13);
// Test 1
// Check if the chequing is being set
assert(dummy.getChequing() == 4545.13);
dummy.setChequing(5942.84);
// Test 2
// Check if the chequing is being set
assert(dummy.getChequing() == 5942.84);
JOptionPane.showMessageDialog(null, "Test cases passed", "testChequing", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 16
* Test case for savings set
*
*/
@Test
public void testSavings() {
BankAutomated BA = new BankAutomated(false);
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
dummy.setSavings(4545.13);
// Test 1
// Check if the savings is being set
assert(dummy.getSavings() == 4545.13);
dummy.setSavings(5942.84);
// Test 2
// Check if the savings is being set
assert(dummy.getSavings() == 5942.84);
JOptionPane.showMessageDialog(null, "Test cases passed", "testSavings", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 17
* Test case for chequing history
*
*/
@Test
public void testChequingHistory() {
BankAutomated BA = new BankAutomated(false);
ArrayList<Transaction> chequingHist = new ArrayList<>();
chequingHist.add(new Transaction("Person 1", "test", 500,1));
chequingHist.add(new Transaction("test", "Person 2", 115,2));
chequingHist.add(new Transaction("Person 3", "test", 200,3));
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
dummy.addChequing(new Transaction("Person 1", "test", 500,4));
dummy.addChequing(new Transaction("test", "Person 2", 115,5));
dummy.addChequing(new Transaction("Person 3", "test", 200,6));
// Test 1
// Check if the chequing history is being set after adding transactions to each customer
for (int i = 0; i < chequingHist.size(); i++)
{
assert(dummy.getChequingHist().get(i).getReceiver().equals(chequingHist.get(i).getReceiver()));
assert(dummy.getChequingHist().get(i).getSender().equals(chequingHist.get(i).getSender()));
assert (dummy.getChequingHist().get(i).getAmount() == chequingHist.get(i).getAmount());
}
JOptionPane.showMessageDialog(null, "Test cases passed", "testChequingHistory", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 18
* Test case for savings history
*
*/
@Test
public void testSavingsHistory() {
BankAutomated BA = new BankAutomated(false);
ArrayList<Transaction> savingsHist = new ArrayList<>();
savingsHist.add(new Transaction("Person 1", "test", 500,1));
savingsHist.add(new Transaction("test", "Person 2", 115,2));
savingsHist.add(new Transaction("Person 3", "test", 200,3));
dummy = BA.createAccount("test", "dummy", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
dummy.addSaving(new Transaction("Person 1", "test", 500,4));
dummy.addSaving(new Transaction("test", "Person 2", 115,5));
dummy.addSaving(new Transaction("Person 3", "test", 200,6));
// Test 1
// Check if the savings history is being set after adding transactions to each customer
for (int i = 0; i < savingsHist.size(); i++)
{
assert(dummy.getSavingsHist().get(i).getReceiver().equals(savingsHist.get(i).getReceiver()));
assert(dummy.getSavingsHist().get(i).getSender().equals(savingsHist.get(i).getSender()));
assert(dummy.getSavingsHist().get(i).getAmount() == savingsHist.get(i).getAmount());
}
JOptionPane.showMessageDialog(null, "Test cases passed", "testCardExpiry", JOptionPane.INFORMATION_MESSAGE);
}
/* Test 19
* Test case for card expiry
*
*/
@Test
public void testSetterGetter() {
BankAutomated BA = new BankAutomated(false);
// Test setters and getters for People objects
People test = new People("John", "Doe", "[email protected]", "416-123-4567");
// Test setter and getters for People objects
assertEquals("John", test.getFirstName());
assertEquals("Doe", test.getLastName());
assertEquals("[email protected]", test.getEmail());
assertEquals("416-123-4567", test.getPhoneNum());
test.setFirstName("Jane");
test.setLastName("Smith");
test.setEmail("[email protected]");
test.setPhoneNum("647-987-6543");
// Test setters and getters for People objects
assertEquals("Jane", test.getFirstName());
assertEquals("Smith", test.getLastName());
assertEquals("[email protected]", test.getEmail());
assertEquals("647-987-6543", test.getPhoneNum());
// Test setter and getters for CA objects
dummy = BA.createAccount("John", "Doe", "416-792-1234", "test street",
"Male", "01/01/1990", "[email protected]", "Hello@World1",
"4417123456789113", "01/01/2027", "555");
dummy.setChequing(500);
dummy.setSavings(1000);
dummy.setBankNumber("12345");
// Test getters for constructor attributes
assertEquals("John", dummy.getFirstName());
assertEquals("Doe", dummy.getLastName());
assertEquals("416-792-1234", dummy.getPhoneNum());
assertEquals("test street", dummy.getAddress());
assertEquals("Male", dummy.getGender());
assertEquals("01/01/1990", dummy.getDob());
assertEquals("[email protected]", dummy.getEmail());
assertEquals("Hello@World1", dummy.getPassword());
assertEquals("4417123456789113", dummy.getCardNum());
assertEquals("01/01/2027", dummy.getCardExpiry());
assertEquals("555", dummy.getCvv());
assert(500 == dummy.getChequing());
assert(1000 == dummy.getSavings());
assertEquals("12345", dummy.getBankNumber());
// Test setters by setting a new value, and using getter to check if value is changed
dummy.setFirstName("Jane");
dummy.setLastName("Smith");
dummy.setPhoneNum("416-987-6543");
dummy.setAddress("321 Bakers St.");
dummy.setGender("Female");
dummy.setDob("02/02/2001");
dummy.setEmail("[email protected]");
dummy.setPassword("123Password@");
dummy.setCardNum("4417987654321098");
dummy.setCardExpiry("02/02/2029");
dummy.setCvv("789");
dummy.setChequing(1200);
dummy.setSavings(900);
dummy.setBankNumber("98765");
// Use getters to see if values were changed
assertEquals("Jane", dummy.getFirstName());
assertEquals("Smith", dummy.getLastName());
assertEquals("416-987-6543", dummy.getPhoneNum());
assertEquals("321 Bakers St.", dummy.getAddress());
assertEquals("Female", dummy.getGender());
assertEquals("02/02/2001", dummy.getDob());
assertEquals("[email protected]", dummy.getEmail());
assertEquals("123Password@", dummy.getPassword());
assertEquals("4417987654321098", dummy.getCardNum());
assertEquals("02/02/2029", dummy.getCardExpiry());
assertEquals("789", dummy.getCvv());
assert(1200 == dummy.getChequing());
assert(900 == dummy.getSavings());
assertEquals("98765", dummy.getBankNumber());
// Add transactions, reports, and requests to respective array lists
// Then use getters to check if value changed to check that both
// setters and getters are working
AD admin = new AD("Mike", "Smith", "[email protected]", "647-123-4568", 105);
Transaction chequing = new Transaction("Chequing", "Savings", 500, 201);
Transaction savings = new Transaction("Savings", "Chequing", 600, 205);
Report report = new Report(dummy, admin, "test");
Request request = new Request("RM", admin, "10/10/2022");
dummy.addChequing(chequing);
dummy.addSaving(savings);
dummy.addReport(report);
dummy.addRequests(request);
// Use getters to test if setters correctly added values (also
// tests if getters work correctly)
assertEquals(chequing, dummy.getChequingHist().get(0));
assertEquals(savings, dummy.getSavingsHist().get(0));
assertEquals(report, dummy.getReportSus().get(0));
assertEquals(request, dummy.getRequests().get(0));
// Test setters and getters for transactions
Transaction transactionTest = new Transaction("Chequing", "Savings", 500, 12345);
assertEquals("Chequing", transactionTest.getSender());
assertEquals("Savings", transactionTest.getReceiver());
assert(500 == transactionTest.getAmount());
assert(12345 == transactionTest.getId());
transactionTest.setSender("Current");
transactionTest.setReceiver("[email protected]");
transactionTest.setAmount(1000);
transactionTest.setId(98765);
assertEquals("Current", transactionTest.getSender());
assertEquals("[email protected]", transactionTest.getReceiver());
assert(1000 == transactionTest.getAmount());
assert(98765 == transactionTest.getId());
// Test setter and getters for reports
Report reportTest = new Report(dummy, admin, "test");
assertEquals(reportTest.getAdmin(), admin);
AD a = new AD("Mojo", "Jojo", "[email protected]", "6471112222", 0);
reportTest.setAdmin(a);
assertEquals(reportTest.getAdmin(), a);