|
@@ -1,12 +1,239 @@
|
1
|
|
-import static org.junit.Assert.*;
|
|
1
|
+import org.junit.Assert;
|
|
2
|
+import org.junit.Test;
|
|
3
|
+
|
2
|
4
|
|
3
|
5
|
public class CheckbookTest {
|
|
6
|
+ private Checkbook checkbook1 = new Checkbook(100.00);
|
|
7
|
+ private Checkbook checkbook2 = new Checkbook(30.00);
|
|
8
|
+ private Payee owner1 = new Payee();
|
|
9
|
+ private Payee owner2 = new Payee();
|
|
10
|
+ private Transaction transactionDebit1 = new Transaction(" ", owner1, TransactionType.DEBIT, 100.00);
|
|
11
|
+ private Transaction transactionCredit1 = new Transaction(" ", owner1, TransactionType.CREDIT, 50.00);
|
|
12
|
+ private Transaction transactionDebit2 = new Transaction(" ", owner2, TransactionType.DEBIT, 100.00);
|
|
13
|
+ private Transaction transactionCredit2 = new Transaction(" ", owner2, TransactionType.CREDIT, 50.00);
|
4
|
14
|
|
5
|
15
|
@org.junit.Before
|
6
|
16
|
public void setUp() throws Exception {
|
|
17
|
+ checkbook1.add(transactionCredit1);
|
|
18
|
+ checkbook1.add(transactionDebit1);
|
|
19
|
+ checkbook2.add(transactionCredit2);
|
|
20
|
+ checkbook2.add(transactionDebit2);
|
7
|
21
|
}
|
8
|
22
|
|
9
|
23
|
@org.junit.After
|
10
|
24
|
public void tearDown() throws Exception {
|
11
|
25
|
}
|
|
26
|
+
|
|
27
|
+ @Test
|
|
28
|
+ public void test1Add() {
|
|
29
|
+ Assert.assertEquals(2, checkbook1.size());
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ @Test
|
|
33
|
+ public void test2Add() {
|
|
34
|
+ checkbook1.add(new Transaction("", new Payee(), TransactionType.DEBIT, 1.00));
|
|
35
|
+ int expected = 3;
|
|
36
|
+ int actual = checkbook1.size();
|
|
37
|
+ Assert.assertEquals(expected, actual);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ @Test
|
|
41
|
+ public void test3Add() {
|
|
42
|
+ checkbook2.add(new Transaction("", owner1, TransactionType.DEBIT, 1.00));
|
|
43
|
+ checkbook2.add(new Transaction("", owner1, TransactionType.DEBIT, 1.50));
|
|
44
|
+ int expected = 4;
|
|
45
|
+ int actual = checkbook2.size();
|
|
46
|
+ Assert.assertEquals(expected, actual);
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ @Test
|
|
50
|
+ public void test1Remove() {
|
|
51
|
+ checkbook1.remove(transactionCredit1);
|
|
52
|
+ int expected = 1;
|
|
53
|
+ int actual = checkbook1.size();
|
|
54
|
+ Assert.assertEquals(expected, actual);
|
|
55
|
+
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ @Test
|
|
59
|
+ public void test2Remove() {
|
|
60
|
+ checkbook1.remove(transactionCredit1);
|
|
61
|
+ checkbook1.remove(transactionDebit1);
|
|
62
|
+ int expected = 0;
|
|
63
|
+ int actual = checkbook1.size();
|
|
64
|
+ Assert.assertEquals(expected, actual);
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ @Test
|
|
68
|
+ public void test1contains() {
|
|
69
|
+ Assert.assertTrue(checkbook1.contains(transactionCredit1));
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ @Test
|
|
73
|
+ public void test2contains() {
|
|
74
|
+ Assert.assertTrue(checkbook1.contains(transactionDebit1));
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ @Test
|
|
78
|
+ public void test3contains() {
|
|
79
|
+ Assert.assertTrue(checkbook2.contains(transactionCredit2));
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ @Test
|
|
83
|
+ public void test1isEmpty() {
|
|
84
|
+ Assert.assertFalse(checkbook2.isEmpty());
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ @Test
|
|
88
|
+ public void test2isEmpty() {
|
|
89
|
+ Checkbook check = new Checkbook();
|
|
90
|
+ Assert.assertTrue(check.isEmpty());
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ @Test
|
|
94
|
+ public void test3isEmpty() {
|
|
95
|
+ Assert.assertFalse(checkbook1.isEmpty());
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ @Test
|
|
99
|
+ public void test1Iterator() {
|
|
100
|
+ Assert.assertTrue(checkbook1.iterator().hasNext());
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ @Test
|
|
104
|
+ public void test2Iterator() {
|
|
105
|
+ Checkbook check = new Checkbook();
|
|
106
|
+ Assert.assertFalse(check.iterator().hasNext());
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ @Test
|
|
110
|
+ public void test1CheckbookValue() {
|
|
111
|
+ Assert.assertEquals(100.00, checkbook1.checkbookValue(), .01);
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ @Test
|
|
115
|
+ public void test2CheckbookValue() {
|
|
116
|
+ Double expected = 30.00;
|
|
117
|
+ Double actual = checkbook2.checkbookValue();
|
|
118
|
+ Assert.assertEquals(expected, actual);
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ @Test
|
|
122
|
+ public void test1ToArray() {
|
|
123
|
+ int expected = 2;
|
|
124
|
+ int actual = checkbook1.toArray().length;
|
|
125
|
+ Assert.assertEquals(expected, actual);
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ @Test
|
|
129
|
+ public void test2ToArray() {
|
|
130
|
+ int expected = 2;
|
|
131
|
+ int actual = checkbook2.toArray().length;
|
|
132
|
+ Assert.assertEquals(expected, actual);
|
|
133
|
+ }
|
|
134
|
+
|
|
135
|
+ @Test
|
|
136
|
+ public void test3ToArray() {
|
|
137
|
+ Checkbook check = new Checkbook();
|
|
138
|
+ int expected = 0;
|
|
139
|
+ int actual = check.toArray().length;
|
|
140
|
+ Assert.assertEquals(expected, actual);
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+ @Test
|
|
144
|
+ public void test1getTransactionForDate() {
|
|
145
|
+ Transaction[] expected = {transactionCredit1, transactionDebit1};
|
|
146
|
+ Transaction[] actual = checkbook1.getTransactionForDate(transactionCredit1.getDate());
|
|
147
|
+ Assert.assertEquals(expected, actual);
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ @Test
|
|
151
|
+ public void test2getTransactionForDate() {
|
|
152
|
+ Transaction[] expected = {transactionCredit2, transactionDebit2};
|
|
153
|
+ Transaction[] actual = checkbook2.getTransactionForDate(transactionCredit2.getDate());
|
|
154
|
+ Assert.assertEquals(expected, actual);
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ @Test
|
|
158
|
+ public void test1getAllTransactionsForPayee() {
|
|
159
|
+ Transaction[] expected = {transactionDebit1, transactionCredit1};
|
|
160
|
+ Transaction[] actual = checkbook1.getAllTransactionsForPayee(owner1);
|
|
161
|
+ Assert.assertEquals(expected, actual);
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ @Test
|
|
165
|
+ public void test2getAllTransactionsForPayee() {
|
|
166
|
+ Transaction[] expected = {transactionDebit2, transactionCredit2};
|
|
167
|
+ Transaction[] actual = checkbook2.getAllTransactionsForPayee(owner2);
|
|
168
|
+ Assert.assertEquals(expected, actual);
|
|
169
|
+ }
|
|
170
|
+
|
|
171
|
+ @Test
|
|
172
|
+ public void test3getAllTransactionsForPayee() {
|
|
173
|
+ Transaction[] expected = {transactionDebit1, transactionCredit1};
|
|
174
|
+ Transaction[] actual = checkbook1.getAllTransactionsForPayee(owner1);
|
|
175
|
+ Assert.assertEquals(expected, actual);
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ @Test
|
|
179
|
+ public void test1getAllDebitTransactions() {
|
|
180
|
+ Transaction[] expected = {transactionDebit2};
|
|
181
|
+ Transaction[] actual = checkbook2.getAllDebitTransactions();
|
|
182
|
+ Assert.assertEquals(expected, actual);
|
|
183
|
+ }
|
|
184
|
+
|
|
185
|
+ @Test
|
|
186
|
+ public void test2getAllDebitTransactions() {
|
|
187
|
+ Transaction[] expected = {transactionDebit1};
|
|
188
|
+ Transaction[] actual = checkbook1.getAllDebitTransactions();
|
|
189
|
+ Assert.assertEquals(expected, actual);
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ @Test
|
|
193
|
+ public void test3getAllDebitTransactions() {
|
|
194
|
+ Checkbook checkbook = new Checkbook();
|
|
195
|
+ Transaction transactionDebit = new Transaction(" ", owner1, TransactionType.DEBIT, 100.00);
|
|
196
|
+ checkbook.add(transactionDebit);
|
|
197
|
+ Transaction[] expected = {transactionDebit};
|
|
198
|
+ Transaction[] actual = checkbook.getAllDebitTransactions();
|
|
199
|
+ Assert.assertEquals(expected, actual);
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ @Test
|
|
203
|
+ public void test1getAllCreditTransactions() {
|
|
204
|
+ Transaction[] expected = {transactionCredit1};
|
|
205
|
+ Transaction[] actual = checkbook1.getAllCreditTransactions();
|
|
206
|
+ Assert.assertEquals(expected, actual);
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ @Test
|
|
210
|
+ public void test2getAllCreditTransactions() {
|
|
211
|
+ Transaction[] expected = {transactionCredit2};
|
|
212
|
+ Transaction[] actual = checkbook2.getAllCreditTransactions();
|
|
213
|
+ Assert.assertEquals(expected, actual);
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ @Test
|
|
217
|
+ public void test3getAllCreditTransactions() {
|
|
218
|
+ Checkbook checkbook = new Checkbook();
|
|
219
|
+ Transaction transactionCredit = new Transaction(" ", owner1, TransactionType.CREDIT, 100.00);
|
|
220
|
+ checkbook.add(transactionCredit);
|
|
221
|
+ Transaction[] expected = {transactionCredit};
|
|
222
|
+ Transaction[] actual = checkbook.getAllCreditTransactions();
|
|
223
|
+ Assert.assertEquals(expected, actual);
|
|
224
|
+ }
|
|
225
|
+
|
|
226
|
+ @Test
|
|
227
|
+ public void test1Clear() {
|
|
228
|
+ checkbook2.clear();
|
|
229
|
+ Assert.assertEquals(0, checkbook2.size());
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ @Test
|
|
233
|
+ public void test2Clear() {
|
|
234
|
+ checkbook1.clear();
|
|
235
|
+ Assert.assertEquals(0, checkbook1.size());
|
|
236
|
+ }
|
|
237
|
+
|
|
238
|
+
|
12
|
239
|
}
|