#8 JenniferChao4 - Checkbook (Finished)

Atvērta
JenniferChao4 vēlas sapludināt 1 revīzijas no JenniferChao4/Checkbook-OldStyle:master uz master

+ 0
- 13
.idea/libraries/Maven__junit_junit_4_0.xml Parādīt failu

@@ -1,13 +0,0 @@
1
-<component name="libraryTable">
2
-  <library name="Maven: junit:junit:4.0">
3
-    <CLASSES>
4
-      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.0/junit-4.0.jar!/" />
5
-    </CLASSES>
6
-    <JAVADOC>
7
-      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.0/junit-4.0-javadoc.jar!/" />
8
-    </JAVADOC>
9
-    <SOURCES>
10
-      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.0/junit-4.0-sources.jar!/" />
11
-    </SOURCES>
12
-  </library>
13
-</component>

+ 13
- 0
.idea/libraries/Maven__junit_junit_4_12.xml Parādīt failu

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: junit:junit:4.12">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml Parādīt failu

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: org.hamcrest:hamcrest-core:1.3">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 1
- 1
Checkbook/pom.xml Parādīt failu

@@ -23,7 +23,7 @@
23 23
         <dependency>
24 24
             <groupId>junit</groupId>
25 25
             <artifactId>junit</artifactId>
26
-            <version>4.0</version>
26
+            <version>4.12</version>
27 27
         </dependency>
28 28
     </dependencies>
29 29
 

+ 152
- 1
Checkbook/src/main/java/Checkbook.java Parādīt failu

@@ -1,5 +1,156 @@
1
+import java.time.LocalDate;
2
+import java.util.ArrayList;
3
+import java.util.Arrays;
4
+import java.util.Collection;
5
+import java.util.Iterator;
6
+
1 7
 public class Checkbook {
2 8
 
3
-    //blind us with your Java eloquence....
9
+    private ArrayList<Transaction> checkBook;
10
+    private Payee owner;
11
+    private Double cashAmount;
12
+
13
+    public Checkbook(Double cashAmount){
14
+        this.cashAmount = cashAmount;
15
+        this.checkBook = new ArrayList<>();
16
+    }
17
+
18
+    public Checkbook(Payee owner, Double cashAmount){
19
+        this.owner = owner;
20
+        this.cashAmount = cashAmount;
21
+        this.checkBook = new ArrayList<>();
22
+    }
23
+
24
+    public int size(){
25
+        return checkBook.size();
26
+    }
27
+
28
+    public boolean isEmpty() {
29
+        return checkBook.isEmpty();
30
+    }
31
+
32
+    public boolean contains(Transaction element){
33
+        return checkBook.contains(element);
34
+    }
35
+
36
+    public void add(Transaction element){
37
+        checkBook.add(element);
38
+        updateCashAmount();
39
+    }
40
+
41
+    public void add(Transaction ... element){
42
+        checkBook.addAll(Arrays.asList(element));
43
+        updateCashAmount();
44
+    }
45
+
46
+    public void remove(Transaction element){
47
+        checkBook.remove(element);
48
+        updateCashAmount();
49
+    }
50
+
51
+    public void remove(Transaction ... element) {
52
+        checkBook.removeAll(Arrays.asList(element));
53
+        updateCashAmount();
54
+    }
55
+
56
+    public Iterator iterator(){
57
+        return checkBook.iterator();
58
+    }
59
+
60
+    public Transaction[] toArray(){
61
+        return checkBook.toArray(new Transaction[0]);
62
+    }
63
+
64
+    public Transaction[] toArray(Transaction[] a){
65
+        return checkBook.toArray(a);
66
+    }
67
+
68
+    public double checkbookValue(){
69
+        double sum = 0;
70
+
71
+        for (Transaction transaction : checkBook) {
72
+            sum += transaction.getAmount();
73
+        }
74
+
75
+        return sum;
76
+    }
77
+
78
+    public Transaction[] getTransactionsForDate(LocalDate aDate){
79
+        ArrayList<Transaction> transactionsOnDate = new ArrayList<>();
80
+
81
+        for (Transaction transaction : checkBook) {
82
+            if (aDate.equals(transaction.getDate())) {
83
+                transactionsOnDate.add(transaction);
84
+            }
85
+        }
86
+
87
+        return transactionsOnDate.toArray(new Transaction[0]);
88
+    }
89
+
90
+    public Transaction[] getAllTransactionsForPayee(Payee payee){
91
+        ArrayList<Transaction> transactionsForPayee = new ArrayList<>();
92
+
93
+        for (Transaction transaction : checkBook) {
94
+            if (transaction.getPayee() == payee) {
95
+                transactionsForPayee.add(transaction);
96
+            }
97
+        }
98
+
99
+        return transactionsForPayee.toArray(new Transaction[0]);
100
+    }
101
+
102
+    public Transaction[] getAllDebitTransactions(){
103
+        ArrayList<Transaction> debitTransactions = new ArrayList<>();
104
+
105
+        for (Transaction transaction : checkBook) {
106
+            if (transaction.getType() == TransactionType.DEBIT) {
107
+                debitTransactions.add(transaction);
108
+            }
109
+        }
110
+
111
+        return debitTransactions.toArray(new Transaction[0]);
112
+    }
113
+
114
+    public Transaction[] getAllCreditTransactions(){
115
+        ArrayList<Transaction> creditTransactions = new ArrayList<>();
116
+
117
+        for (Transaction transaction : checkBook) {
118
+            if (transaction.getType() == TransactionType.CREDIT) {
119
+                creditTransactions.add(transaction);
120
+            }
121
+        }
122
+
123
+        return creditTransactions.toArray(new Transaction[0]);
124
+    }
125
+
126
+    public boolean containsAll(Collection c){
127
+        return checkBook.containsAll(c);
128
+    }
129
+
130
+    public void addAll(Collection c){
131
+        checkBook.addAll(c);
132
+        updateCashAmount();
133
+    }
134
+
135
+    public void removeAll(Collection c){
136
+        checkBook.removeAll(c);
137
+        updateCashAmount();
138
+    }
139
+
140
+    public void clear(){
141
+        checkBook.clear();
142
+        updateCashAmount();
143
+    }
144
+
145
+    public Payee getOwner(){
146
+        return owner;
147
+    }
148
+
149
+    public Double getCashAmount(){
150
+        return cashAmount;
151
+    }
4 152
 
153
+    private void updateCashAmount() {
154
+        this.cashAmount = checkbookValue();
155
+    }
5 156
 }

+ 32
- 1
Checkbook/src/main/java/GenericAccount.java Parādīt failu

@@ -1,3 +1,34 @@
1 1
 
2
-public class GenericAccount {
2
+public class GenericAccount<T extends AccountBook> {
3
+
4
+    private Checkbook checkbook;
5
+    private Payee owner;
6
+    private Double balance;
7
+
8
+    public GenericAccount(Double balance){
9
+        this.checkbook = new Checkbook(0.0);
10
+        this.balance = balance;
11
+    }
12
+
13
+    public GenericAccount(Payee owner, Double balance){
14
+        this.checkbook = new Checkbook(owner, 0.0);
15
+        this.owner = owner;
16
+        this.balance = balance;
17
+    }
18
+
19
+    public Checkbook getCheckbook(){
20
+        return checkbook;
21
+    }
22
+
23
+    public Payee getOwner(){
24
+        return owner;
25
+    }
26
+
27
+    public void setOwner(Payee owner){
28
+        this.owner = owner;
29
+    }
30
+
31
+    public Double getBalance(){
32
+        return balance + checkbook.getCashAmount();
33
+    }
3 34
 }

+ 9
- 0
Checkbook/src/main/java/Payee.java Parādīt failu

@@ -4,6 +4,15 @@ public class Payee {
4 4
     private String givenName;
5 5
     private String emailAddress;
6 6
 
7
+    public Payee(){
8
+    }
9
+
10
+    public Payee(String familyName, String givenName, String emailAddress){
11
+        this.familyName = familyName;
12
+        this.givenName = givenName;
13
+        this.emailAddress = emailAddress;
14
+    }
15
+
7 16
     public String getFamilyName() {
8 17
         return familyName;
9 18
     }

+ 7
- 4
Checkbook/src/main/java/Transaction.java Parādīt failu

@@ -1,15 +1,18 @@
1 1
 import java.time.LocalDate;
2
+import java.util.concurrent.atomic.AtomicInteger;
2 3
 import java.util.concurrent.atomic.AtomicReference;
3 4
 
4
-public class Transaction {
5
-    private final AtomicReference<Integer> id = new AtomicReference<Integer>();
6
-    private final AtomicReference<LocalDate> date = new AtomicReference<LocalDate>();
5
+public class Transaction implements AccountBook {
6
+    private final int transactionID;
7
+    private static final AtomicInteger id = new AtomicInteger(0);
8
+    private final AtomicReference<LocalDate> date = new AtomicReference<>(LocalDate.now());
7 9
     private String memo;
8 10
     private Payee payee;
9 11
     private TransactionType typee; // Credit (reduces the checkbook), Debit (increases the checkbook)
10 12
     private Double amount;
11 13
 
12 14
     public Transaction(String memo, Payee payee, TransactionType typee, Double amount) {
15
+        this.transactionID = id.incrementAndGet();
13 16
         this.typee = typee;
14 17
         this.memo = memo;
15 18
         this.payee = payee;
@@ -17,7 +20,7 @@ public class Transaction {
17 20
     }
18 21
 
19 22
     public Integer getId() {
20
-        return id.get();
23
+        return transactionID;
21 24
     }
22 25
 
23 26
     public LocalDate getDate() {

+ 313
- 5
Checkbook/src/test/java/CheckbookTest.java Parādīt failu

@@ -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
 }

+ 37
- 0
Checkbook/src/test/java/GenericAccountTest.java Parādīt failu

@@ -0,0 +1,37 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
4
+public class GenericAccountTest {
5
+
6
+    private Payee owner = new Payee();
7
+    private GenericAccount blankAccount = new GenericAccount(100.0);
8
+    private GenericAccount account = new GenericAccount(owner, 100.0);
9
+
10
+    @Test
11
+    public void getCheckbook() {
12
+        Assert.assertEquals( 0, blankAccount.getCheckbook().getCashAmount(), 1e-15);
13
+    }
14
+
15
+    @Test
16
+    public void getOwner() {
17
+        Assert.assertNull(blankAccount.getOwner());
18
+    }
19
+
20
+    @Test
21
+    public void setOwner() {
22
+        Payee newOwner = new Payee();
23
+        account.setOwner(newOwner);
24
+
25
+        Assert.assertEquals(newOwner, account.getOwner());
26
+    }
27
+
28
+    @Test
29
+    public void getBalance() {
30
+        Checkbook checkbook = account.getCheckbook();
31
+        Transaction transaction = new Transaction(null, null, TransactionType.DEBIT, 50.00);
32
+        Transaction transaction2 = new Transaction(null, null, TransactionType.CREDIT, 10.00);
33
+        checkbook.add(transaction, transaction2);
34
+
35
+        Assert.assertEquals(140.00, account.getBalance(), 1e-15);
36
+    }
37
+}

+ 45
- 0
Checkbook/src/test/java/PayeeTest.java Parādīt failu

@@ -0,0 +1,45 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
4
+import static org.junit.Assert.*;
5
+
6
+public class PayeeTest {
7
+
8
+    private Payee payee = new Payee("Chao", "Jenn", "jchao@zcw.com");
9
+
10
+    @Test
11
+    public void getFamilyName() {
12
+        Assert.assertEquals("Chao", payee.getFamilyName());
13
+    }
14
+
15
+    @Test
16
+    public void setFamilyName() {
17
+        payee.setFamilyName("C.");
18
+
19
+        Assert.assertEquals("C.", payee.getFamilyName());
20
+    }
21
+
22
+    @Test
23
+    public void getGivenName() {
24
+        Assert.assertEquals("Jenn", payee.getGivenName());
25
+    }
26
+
27
+    @Test
28
+    public void setGivenName() {
29
+        payee.setGivenName("Jennifer");
30
+
31
+        Assert.assertEquals("Jennifer", payee.getGivenName());
32
+    }
33
+
34
+    @Test
35
+    public void getEmailAddress() {
36
+        Assert.assertEquals("jchao@zcw.com", payee.getEmailAddress());
37
+    }
38
+
39
+    @Test
40
+    public void setEmailAddress() {
41
+        payee.setEmailAddress("jenniferchao@zcw.com");
42
+
43
+        Assert.assertEquals("jenniferchao@zcw.com", payee.getEmailAddress());
44
+    }
45
+}

+ 57
- 0
Checkbook/src/test/java/TransactionTest.java Parādīt failu

@@ -0,0 +1,57 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
4
+import java.time.LocalDate;
5
+
6
+public class TransactionTest {
7
+
8
+    private Payee anonymous = new Payee();
9
+
10
+    private Transaction transaction = new Transaction("test", anonymous, TransactionType.DEBIT, 1.00);
11
+
12
+    @Test
13
+    public void getId() {
14
+        Transaction transaction2 = new Transaction("test", anonymous, TransactionType.CREDIT, 1.00);
15
+        Assert.assertEquals(1, transaction2.getId() - transaction.getId(), 1e-15);
16
+    }
17
+
18
+    @Test
19
+    public void getDate() {
20
+        Assert.assertEquals(LocalDate.now(), transaction.getDate());
21
+    }
22
+
23
+    @Test
24
+    public void getType() {
25
+        Assert.assertEquals(TransactionType.DEBIT, transaction.getType());
26
+    }
27
+
28
+    @Test
29
+    public void getMemo() {
30
+        Assert.assertEquals("test", transaction.getMemo());
31
+    }
32
+
33
+    @Test
34
+    public void setMemo() {
35
+        transaction.setMemo("new memo");
36
+
37
+        Assert.assertEquals("new memo", transaction.getMemo());
38
+    }
39
+
40
+    @Test
41
+    public void getPayee() {
42
+        Assert.assertEquals(anonymous, transaction.getPayee());
43
+    }
44
+
45
+    @Test
46
+    public void setPayee() {
47
+        Payee anonymous2 = new Payee();
48
+        transaction.setPayee(anonymous2);
49
+
50
+        Assert.assertEquals(anonymous2, transaction.getPayee());
51
+    }
52
+
53
+    @Test
54
+    public void getAmount() {
55
+        Assert.assertEquals(1.00, transaction.getAmount(), 1e-15);
56
+    }
57
+}