|
@@ -1,12 +1,320 @@
|
1
|
|
-import static org.junit.Assert.*;
|
|
1
|
+import org.junit.Assert;
|
|
2
|
+import org.junit.Before;
|
|
3
|
+import org.junit.Test;
|
|
4
|
+
|
|
5
|
+import java.time.LocalDate;
|
|
6
|
+import java.util.ArrayList;
|
|
7
|
+import java.util.Iterator;
|
2
|
8
|
|
3
|
9
|
public class CheckbookTest {
|
4
|
10
|
|
5
|
|
- @org.junit.Before
|
6
|
|
- public void setUp() throws Exception {
|
|
11
|
+ private Checkbook blankCheckbook = new Checkbook(0.0);
|
|
12
|
+
|
|
13
|
+ private Payee owner = new Payee("Jenn", "Chao", "jchao@zcw.com");
|
|
14
|
+ private Checkbook checkbook = new Checkbook(owner, 0.0);
|
|
15
|
+
|
|
16
|
+ private Payee anonymous = new Payee();
|
|
17
|
+ private Payee anonymous2 = new Payee();
|
|
18
|
+
|
|
19
|
+ private Transaction debit1 = new Transaction(null, anonymous, TransactionType.DEBIT, 10.00);
|
|
20
|
+ private Transaction debit2 = new Transaction(null, anonymous2, TransactionType.DEBIT, 153.73);
|
|
21
|
+ private Transaction credit1 = new Transaction(null, anonymous, TransactionType.CREDIT, 19.54);
|
|
22
|
+ private Transaction credit2 = new Transaction(null, anonymous2, TransactionType.CREDIT, 49.25);
|
|
23
|
+
|
|
24
|
+ @Before
|
|
25
|
+ public void setUp(){
|
|
26
|
+ checkbook.add(debit1, debit2, credit1, credit2);
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ ////////// ////////// //////////
|
|
30
|
+
|
|
31
|
+ @Test
|
|
32
|
+ public void checkbookValue() {
|
|
33
|
+ checkbook.clear();
|
|
34
|
+
|
|
35
|
+ Double expected = 0.0;
|
|
36
|
+ Double actual = checkbook.checkbookValue();
|
|
37
|
+
|
|
38
|
+ Assert.assertEquals(expected, actual);
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ @Test
|
|
42
|
+ public void checkbookValue1() {
|
|
43
|
+ checkbook.clear();
|
|
44
|
+ checkbook.add(debit1, credit1);
|
|
45
|
+
|
|
46
|
+ Double expected = -9.54;
|
|
47
|
+ Double actual = checkbook.checkbookValue();
|
|
48
|
+
|
|
49
|
+ Assert.assertEquals(expected, actual);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ @Test
|
|
53
|
+ public void checkbookValue2() {
|
|
54
|
+ Double expected = 94.94;
|
|
55
|
+ Double actual = checkbook.checkbookValue();
|
|
56
|
+
|
|
57
|
+ Assert.assertEquals(expected, actual);
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ ////////// ////////// //////////
|
|
61
|
+
|
|
62
|
+ @Test
|
|
63
|
+ public void getTransactionsForDate() {
|
|
64
|
+ Transaction[] expected = new Transaction[] {debit1, debit2, credit1, credit2};
|
|
65
|
+ Transaction[] actual = checkbook.getTransactionsForDate(LocalDate.now());
|
|
66
|
+
|
|
67
|
+ Assert.assertArrayEquals(expected, actual);
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ @Test
|
|
71
|
+ public void getTransactionsForDate1() {
|
|
72
|
+ LocalDate yesterday = LocalDate.of(2018, 12, 6);
|
|
73
|
+
|
|
74
|
+ Transaction[] expected = new Transaction[0];
|
|
75
|
+ Transaction[] actual = checkbook.getTransactionsForDate(yesterday);
|
|
76
|
+
|
|
77
|
+ Assert.assertArrayEquals(expected, actual);
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ @Test
|
|
81
|
+ public void getTransactionsForDate2() {
|
|
82
|
+ Transaction[] expected = new Transaction[] {debit1, debit2, credit1, credit2};
|
|
83
|
+ Transaction[] actual = checkbook.getTransactionsForDate(debit1.getDate());
|
|
84
|
+
|
|
85
|
+ Assert.assertArrayEquals(expected, actual);
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ ////////// ////////// //////////
|
|
89
|
+
|
|
90
|
+ @Test
|
|
91
|
+ public void getAllTransactionsForPayee() {
|
|
92
|
+ Transaction[] expected = new Transaction[] {debit1, credit1};
|
|
93
|
+ Transaction[] actual = checkbook.getAllTransactionsForPayee(anonymous);
|
|
94
|
+
|
|
95
|
+ Assert.assertArrayEquals(expected, actual);
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ @Test
|
|
99
|
+ public void getAllTransactionsForPayee1() {
|
|
100
|
+ Transaction[] expected = new Transaction[] {debit2, credit2};
|
|
101
|
+ Transaction[] actual = checkbook.getAllTransactionsForPayee(anonymous2);
|
|
102
|
+
|
|
103
|
+ Assert.assertArrayEquals(expected, actual);
|
7
|
104
|
}
|
8
|
105
|
|
9
|
|
- @org.junit.After
|
10
|
|
- public void tearDown() throws Exception {
|
|
106
|
+ @Test
|
|
107
|
+ public void getAllTransactionsForPayee2() {
|
|
108
|
+ Transaction[] expected = new Transaction[0];
|
|
109
|
+ Transaction[] actual = checkbook.getAllTransactionsForPayee(new Payee());
|
|
110
|
+
|
|
111
|
+ Assert.assertArrayEquals(expected, actual);
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ ////////// ////////// //////////
|
|
115
|
+
|
|
116
|
+ @Test
|
|
117
|
+ public void getAllDebitTransactions() {
|
|
118
|
+ Transaction[] expected = new Transaction[] {debit1, debit2};
|
|
119
|
+ Transaction[] actual = checkbook.getAllDebitTransactions();
|
|
120
|
+
|
|
121
|
+ Assert.assertArrayEquals(expected, actual);
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ @Test
|
|
125
|
+ public void getAllDebitTransactions1() {
|
|
126
|
+ checkbook.remove(debit2);
|
|
127
|
+
|
|
128
|
+ Transaction[] expected = new Transaction[] {debit1};
|
|
129
|
+ Transaction[] actual = checkbook.getAllDebitTransactions();
|
|
130
|
+
|
|
131
|
+ Assert.assertArrayEquals(expected, actual);
|
11
|
132
|
}
|
|
133
|
+
|
|
134
|
+ @Test
|
|
135
|
+ public void getAllDebitTransactions2() {
|
|
136
|
+ checkbook.remove(debit1, debit2);
|
|
137
|
+
|
|
138
|
+ Transaction[] expected = new Transaction[0];
|
|
139
|
+ Transaction[] actual = checkbook.getAllDebitTransactions();
|
|
140
|
+
|
|
141
|
+ Assert.assertArrayEquals(expected, actual);
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+ ////////// ////////// //////////
|
|
145
|
+
|
|
146
|
+ @Test
|
|
147
|
+ public void getAllCreditTransactions() {
|
|
148
|
+ Transaction[] expected = new Transaction[] {credit1, credit2};
|
|
149
|
+ Transaction[] actual = checkbook.getAllCreditTransactions();
|
|
150
|
+
|
|
151
|
+ Assert.assertArrayEquals(expected, actual);
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+ @Test
|
|
155
|
+ public void getAllCreditTransactions1() {
|
|
156
|
+ checkbook.remove(credit1);
|
|
157
|
+
|
|
158
|
+ Transaction[] expected = new Transaction[] {credit2};
|
|
159
|
+ Transaction[] actual = checkbook.getAllCreditTransactions();
|
|
160
|
+
|
|
161
|
+ Assert.assertArrayEquals(expected, actual);
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ @Test
|
|
165
|
+ public void getAllCreditTransactions2() {
|
|
166
|
+ checkbook.remove(credit1, credit2);
|
|
167
|
+
|
|
168
|
+ Transaction[] expected = new Transaction[0];
|
|
169
|
+ Transaction[] actual = checkbook.getAllCreditTransactions();
|
|
170
|
+
|
|
171
|
+ Assert.assertArrayEquals(expected, actual);
|
|
172
|
+ }
|
|
173
|
+
|
|
174
|
+ ////////// ////////// //////////
|
|
175
|
+
|
|
176
|
+ @Test
|
|
177
|
+ public void size() {
|
|
178
|
+ int expected = 4;
|
|
179
|
+ int actual = checkbook.size();
|
|
180
|
+
|
|
181
|
+ Assert.assertEquals(expected, actual);
|
|
182
|
+ }
|
|
183
|
+
|
|
184
|
+ @Test
|
|
185
|
+ public void isEmpty() {
|
|
186
|
+ boolean expected = false;
|
|
187
|
+ boolean actual = checkbook.isEmpty();
|
|
188
|
+
|
|
189
|
+ Assert.assertEquals(expected, actual);
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ @Test
|
|
193
|
+ public void contains() {
|
|
194
|
+ boolean expected = true;
|
|
195
|
+ boolean actual = checkbook.contains(debit1);
|
|
196
|
+
|
|
197
|
+ Assert.assertEquals(expected, actual);
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ @Test
|
|
201
|
+ public void add() {
|
|
202
|
+ Transaction transaction = new Transaction(null, new Payee(), TransactionType.DEBIT, 1.00);
|
|
203
|
+ checkbook.add(transaction);
|
|
204
|
+
|
|
205
|
+ boolean expected = true;
|
|
206
|
+ boolean actual = checkbook.contains(transaction);
|
|
207
|
+
|
|
208
|
+ Assert.assertEquals(expected, actual);
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ @Test
|
|
212
|
+ public void add1() {
|
|
213
|
+ Transaction transaction = new Transaction(null, new Payee(), TransactionType.DEBIT, 1.00);
|
|
214
|
+ Transaction transaction1 = new Transaction(null, new Payee(), TransactionType.CREDIT, 2.00);
|
|
215
|
+ checkbook.add(transaction, transaction1);
|
|
216
|
+
|
|
217
|
+ boolean expected = true;
|
|
218
|
+ boolean actual = checkbook.contains(transaction) && checkbook.contains(transaction1);
|
|
219
|
+
|
|
220
|
+ Assert.assertEquals(expected, actual);
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ @Test
|
|
224
|
+ public void remove() {
|
|
225
|
+ checkbook.remove(debit1);
|
|
226
|
+
|
|
227
|
+ boolean expected = false;
|
|
228
|
+ boolean actual = checkbook.contains(debit1);
|
|
229
|
+
|
|
230
|
+ Assert.assertEquals(expected, actual);
|
|
231
|
+ }
|
|
232
|
+
|
|
233
|
+ @Test
|
|
234
|
+ public void remove1() {
|
|
235
|
+ checkbook.remove(debit2, credit1);
|
|
236
|
+
|
|
237
|
+ boolean expected = false;
|
|
238
|
+ boolean actual = checkbook.contains(debit2) && checkbook.contains(credit1);
|
|
239
|
+
|
|
240
|
+ Assert.assertEquals(expected, actual);
|
|
241
|
+ }
|
|
242
|
+
|
|
243
|
+ @Test
|
|
244
|
+ public void iterator() {
|
|
245
|
+ Assert.assertTrue(checkbook.iterator() instanceof Iterator);
|
|
246
|
+ }
|
|
247
|
+
|
|
248
|
+ @Test
|
|
249
|
+ public void toArray() {
|
|
250
|
+ Transaction[] expected = new Transaction[] {debit1, debit2, credit1, credit2};
|
|
251
|
+ Transaction[] actual = checkbook.toArray();
|
|
252
|
+
|
|
253
|
+ Assert.assertArrayEquals(expected, actual);
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ @Test
|
|
257
|
+ public void toArray1() {
|
|
258
|
+ Transaction[] expected = new Transaction[] {debit1, debit2, credit1, credit2};
|
|
259
|
+ Transaction[] actual = checkbook.toArray(new Transaction[0]);
|
|
260
|
+
|
|
261
|
+ Assert.assertArrayEquals(expected, actual);
|
|
262
|
+ }
|
|
263
|
+
|
|
264
|
+ @Test
|
|
265
|
+ public void containsAll() {
|
|
266
|
+ ArrayList<Transaction> arrayList = new ArrayList<>();
|
|
267
|
+ arrayList.add(debit1); arrayList.add(credit2);
|
|
268
|
+
|
|
269
|
+ Assert.assertTrue(checkbook.containsAll(arrayList));
|
|
270
|
+ }
|
|
271
|
+
|
|
272
|
+ @Test
|
|
273
|
+ public void addAll() {
|
|
274
|
+ Transaction transaction = new Transaction(null, anonymous, TransactionType.CREDIT, 2.00);
|
|
275
|
+ Transaction transaction2 = new Transaction(null, anonymous2, TransactionType.DEBIT, 8.88);
|
|
276
|
+ ArrayList<Transaction> arrayList = new ArrayList<>();
|
|
277
|
+ arrayList.add(transaction); arrayList.add(transaction2);
|
|
278
|
+
|
|
279
|
+ checkbook.addAll(arrayList);
|
|
280
|
+
|
|
281
|
+ Assert.assertTrue(checkbook.containsAll(arrayList));
|
|
282
|
+ }
|
|
283
|
+
|
|
284
|
+ @Test
|
|
285
|
+ public void removeAll() {
|
|
286
|
+ Transaction transaction = new Transaction(null, anonymous, TransactionType.CREDIT, 2.00);
|
|
287
|
+ Transaction transaction2 = new Transaction(null, anonymous2, TransactionType.DEBIT, 8.88);
|
|
288
|
+ ArrayList<Transaction> arrayList = new ArrayList<>();
|
|
289
|
+ arrayList.add(transaction); arrayList.add(transaction2); arrayList.add(debit1); arrayList.add(credit2);
|
|
290
|
+
|
|
291
|
+ checkbook.removeAll(arrayList);
|
|
292
|
+
|
|
293
|
+ Assert.assertEquals(2, checkbook.size());
|
|
294
|
+ Assert.assertFalse(checkbook.containsAll(arrayList));
|
|
295
|
+ }
|
|
296
|
+
|
|
297
|
+ @Test
|
|
298
|
+ public void clear() {
|
|
299
|
+ checkbook.clear();
|
|
300
|
+
|
|
301
|
+ Assert.assertEquals(0, checkbook.size());
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ @Test
|
|
305
|
+ public void getOwner() {
|
|
306
|
+ Assert.assertEquals(owner, checkbook.getOwner());
|
|
307
|
+ }
|
|
308
|
+
|
|
309
|
+ @Test
|
|
310
|
+ public void getOwner1() {
|
|
311
|
+ Assert.assertNull(blankCheckbook.getOwner());
|
|
312
|
+ }
|
|
313
|
+
|
|
314
|
+ @Test
|
|
315
|
+ public void getCashAmount() {
|
|
316
|
+ Assert.assertEquals(94.94, checkbook.getCashAmount(), 1e-15);
|
|
317
|
+ }
|
|
318
|
+
|
|
319
|
+ ////////// ////////// //////////
|
12
|
320
|
}
|