-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAccountTest.java
More file actions
144 lines (114 loc) · 4.52 KB
/
AccountTest.java
File metadata and controls
144 lines (114 loc) · 4.52 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
package io.zipcoder;
import org.junit.Assert;
import org.junit.Test;
public class AccountTest {
// Helper method to create a concrete account for testing
// Since Account is abstract, we need a concrete implementation for testing
private Account createTestAccount(Object accountHolder, Double balance, String accountNumber) {
// This will need a concrete implementation like CheckingAccount
return new CheckingAccount(accountHolder, balance, accountNumber, true);
}
@Test
public void testGetAccountHolder() {
// Given
Person accountHolder = new Person("John", "Doe", "john@example.com", "555-1234");
Account account = createTestAccount(accountHolder, 1000.0, "ACC001");
// When
Object actualHolder = account.getAccountHolder();
// Then
Assert.assertEquals(accountHolder, actualHolder);
}
@Test
public void testGetBalance() {
// Given
Person accountHolder = new Person("Jane", "Smith", "jane@example.com", "555-5678");
Double expectedBalance = 1500.0;
Account account = createTestAccount(accountHolder, expectedBalance, "ACC002");
// When
Double actualBalance = account.getBalance();
// Then
Assert.assertEquals(expectedBalance, actualBalance, 0.01);
}
@Test
public void testGetAccountNumber() {
// Given
Person accountHolder = new Person("Bob", "Jones", "bob@example.com", "555-9999");
String expectedAccountNumber = "ACC003";
Account account = createTestAccount(accountHolder, 500.0, expectedAccountNumber);
// When
String actualAccountNumber = account.getAccountNumber();
// Then
Assert.assertEquals(expectedAccountNumber, actualAccountNumber);
}
@Test
public void testCredit() {
// Given
Person accountHolder = new Person("Alice", "Brown", "alice@example.com", "555-1111");
Account account = createTestAccount(accountHolder, 1000.0, "ACC004");
Double creditAmount = 500.0;
// When
account.credit(creditAmount);
// Then
Double expectedBalance = 1500.0;
Assert.assertEquals(expectedBalance, account.getBalance(), 0.01);
}
@Test
public void testDebit() {
// Given
Person accountHolder = new Person("Charlie", "Wilson", "charlie@example.com", "555-2222");
Account account = createTestAccount(accountHolder, 1000.0, "ACC005");
Double debitAmount = 300.0;
// When
account.debit(debitAmount);
// Then
Double expectedBalance = 700.0;
Assert.assertEquals(expectedBalance, account.getBalance(), 0.01);
}
@Test
public void testGetTransactions() {
// Given
Person accountHolder = new Person("David", "Miller", "david@example.com", "555-3333");
Account account = createTestAccount(accountHolder, 1000.0, "ACC006");
// When
account.credit(200.0);
account.debit(100.0);
Object transactions = account.getTransactions();
// Then
Assert.assertNotNull(transactions);
}
@Test
public void testTransactionRecordingAfterCredit() {
// Given
Person accountHolder = new Person("Eve", "Davis", "eve@example.com", "555-4444");
Account account = createTestAccount(accountHolder, 1000.0, "ACC007");
// When
account.credit(250.0);
Object transactions = account.getTransactions();
// Then
Assert.assertNotNull(transactions);
// Students should implement a way to verify that the transaction was recorded
}
@Test
public void testTransactionRecordingAfterDebit() {
// Given
Person accountHolder = new Person("Frank", "Garcia", "frank@example.com", "555-5555");
Account account = createTestAccount(accountHolder, 1000.0, "ACC008");
// When
account.debit(150.0);
Object transactions = account.getTransactions();
// Then
Assert.assertNotNull(transactions);
// Students should implement a way to verify that the transaction was recorded
}
@Test
public void testSetBalance() {
// Given
Person accountHolder = new Person("Grace", "Martinez", "grace@example.com", "555-6666");
Account account = createTestAccount(accountHolder, 1000.0, "ACC009");
Double newBalance = 2000.0;
// When
account.setBalance(newBalance);
// Then
Assert.assertEquals(newBalance, account.getBalance(), 0.01);
}
}