Skip to content

Commit 7934e5a

Browse files
authored
Merge pull request #6 from ZipCodeCore/copilot/add-unit-tests-structure
Add TDD unit tests for bank account system implementation
2 parents a5ada85 + a36f702 commit 7934e5a

13 files changed

Lines changed: 1113 additions & 0 deletions

TESTING_GUIDE.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Unit Tests Guide
2+
3+
This project includes comprehensive unit tests to guide your implementation of the bank account system.
4+
5+
## Test Overview
6+
7+
The tests are organized into the following test classes:
8+
9+
### 1. PersonTest (9 tests)
10+
Tests for the `Person` class which represents an individual account holder with:
11+
- First name, last name, email, phone number
12+
- Getters and setters for all properties
13+
14+
### 2. BusinessTest (3 tests)
15+
Tests for the `Business` class which represents a business account holder with:
16+
- Business name
17+
- Getter and setter for business name
18+
19+
### 3. AccountTest (10 tests)
20+
Tests for the abstract `Account` class which includes:
21+
- Account holder (Person or Business)
22+
- Balance management
23+
- Account number
24+
- Credit and debit operations
25+
- Transaction history tracking
26+
27+
### 4. CheckingAccountTest (9 tests)
28+
Tests for `CheckingAccount` which extends `Account` and adds:
29+
- **Overdraft protection** - a boolean flag
30+
- When `true`: Cannot withdraw more than the current balance
31+
- When `false`: Can overdraw the account (negative balance allowed)
32+
33+
### 5. SavingsAccountTest (11 tests)
34+
Tests for `SavingsAccount` which extends `Account` and includes:
35+
- **Interest rate** - ability to earn interest
36+
- **Interest application** - `applyInterest()` method that adds interest to balance
37+
- **Overdraft protection** - Always enabled (cannot go negative)
38+
39+
Formula: `new balance = current balance + (current balance × interest rate)`
40+
41+
### 6. InvestmentAccountTest (12 tests)
42+
Tests for `InvestmentAccount` which extends `Account` and includes:
43+
- **Interest rate** - typically higher than savings accounts
44+
- **Interest application** - `applyInterest()` method
45+
- **No overdraft protection** - Can go negative
46+
- Interest applies even to negative balances
47+
48+
Formula: `new balance = current balance + (current balance × interest rate)`
49+
50+
## Running the Tests
51+
52+
To run all tests:
53+
```bash
54+
mvn test
55+
```
56+
57+
To run a specific test class:
58+
```bash
59+
mvn test -Dtest=PersonTest
60+
mvn test -Dtest=CheckingAccountTest
61+
```
62+
63+
## Implementation Strategy
64+
65+
1. **Start with the simple classes**: Implement `Person` and `Business` first
66+
- These have no dependencies on other classes
67+
- Run `mvn test -Dtest=PersonTest` to verify
68+
69+
2. **Implement the abstract Account class**: Create the base functionality
70+
- Define fields for account holder, balance, account number
71+
- Implement basic credit/debit operations
72+
- Add transaction tracking (consider using an ArrayList)
73+
74+
3. **Implement CheckingAccount**: Extend Account
75+
- Add overdraft protection field
76+
- Override `debit()` to respect overdraft protection
77+
78+
4. **Implement SavingsAccount**: Extend Account
79+
- Add interest rate field
80+
- Implement `applyInterest()` method
81+
- Override `debit()` to prevent overdrafts
82+
83+
5. **Implement InvestmentAccount**: Extend Account
84+
- Add interest rate field
85+
- Implement `applyInterest()` method
86+
- Keep default `debit()` behavior (allows overdrafts)
87+
88+
## Test-Driven Development (TDD)
89+
90+
The tests are written before the implementation. As you implement each class:
91+
92+
1. Run the tests - they will fail initially
93+
2. Implement the minimal code to make one test pass
94+
3. Run the tests again
95+
4. Repeat until all tests pass
96+
97+
## Expected Test Results
98+
99+
Initially, all **53 tests will fail** because the stub implementations only have TODO comments.
100+
101+
As you complete the implementation:
102+
- Person: 9 tests should pass
103+
- Business: 3 tests should pass
104+
- Account + CheckingAccount: ~19 tests should pass
105+
- SavingsAccount: 11 tests should pass
106+
- InvestmentAccount: 12 tests should pass
107+
108+
**Goal**: All 53 tests passing ✓
109+
110+
## Key Concepts Tested
111+
112+
- **Encapsulation**: Getters and setters for private fields
113+
- **Inheritance**: Account subclasses extend the abstract Account class
114+
- **Polymorphism**: Account holder can be Person or Business
115+
- **Business logic**: Overdraft protection, interest calculation
116+
- **State management**: Balance updates, transaction tracking
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,47 @@
11
package io.zipcoder;
22

33
public abstract class Account {
4+
private Object accountHolder;
5+
private Double balance;
6+
private String accountNumber;
7+
// TODO: Add a field to track transactions
8+
9+
public Account(Object accountHolder, Double balance, String accountNumber) {
10+
// TODO: Implement constructor
11+
}
12+
13+
public Object getAccountHolder() {
14+
// TODO: Implement getter
15+
return null;
16+
}
17+
18+
public Double getBalance() {
19+
// TODO: Implement getter
20+
return null;
21+
}
22+
23+
public void setBalance(Double balance) {
24+
// TODO: Implement setter
25+
}
26+
27+
public String getAccountNumber() {
28+
// TODO: Implement getter
29+
return null;
30+
}
31+
32+
public void credit(Double amount) {
33+
// TODO: Implement credit method (add money to account)
34+
// TODO: Record this transaction
35+
}
36+
37+
public void debit(Double amount) {
38+
// TODO: Implement debit method (remove money from account)
39+
// TODO: Record this transaction
40+
}
41+
42+
public Object getTransactions() {
43+
// TODO: Implement method to return transaction history
44+
return null;
45+
}
446
}
47+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.zipcoder;
2+
3+
public class Business {
4+
private String businessName;
5+
6+
public Business(String businessName) {
7+
// TODO: Implement constructor
8+
}
9+
10+
public String getBusinessName() {
11+
// TODO: Implement getter
12+
return null;
13+
}
14+
15+
public void setBusinessName(String businessName) {
16+
// TODO: Implement setter
17+
}
18+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.zipcoder;
2+
3+
public class CheckingAccount extends Account {
4+
private boolean overdraftProtection;
5+
6+
public CheckingAccount(Object accountHolder, Double balance, String accountNumber, boolean overdraftProtection) {
7+
super(accountHolder, balance, accountNumber);
8+
// TODO: Implement constructor
9+
}
10+
11+
public boolean getOverdraftProtection() {
12+
// TODO: Implement getter
13+
return false;
14+
}
15+
16+
public void setOverdraftProtection(boolean overdraftProtection) {
17+
// TODO: Implement setter
18+
}
19+
20+
@Override
21+
public void debit(Double amount) {
22+
// TODO: Implement debit method
23+
// If overdraftProtection is true, don't allow balance to go negative
24+
// If overdraftProtection is false, allow balance to go negative
25+
}
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.zipcoder;
2+
3+
public class InvestmentAccount extends Account {
4+
private Double interestRate;
5+
6+
public InvestmentAccount(Object accountHolder, Double balance, String accountNumber, Double interestRate) {
7+
super(accountHolder, balance, accountNumber);
8+
// TODO: Implement constructor
9+
}
10+
11+
public Double getInterestRate() {
12+
// TODO: Implement getter
13+
return null;
14+
}
15+
16+
public void setInterestRate(Double interestRate) {
17+
// TODO: Implement setter
18+
}
19+
20+
public void applyInterest() {
21+
// TODO: Implement method to apply interest to the balance
22+
// New balance = current balance + (current balance * interest rate)
23+
// Note: Interest applies even to negative balances
24+
}
25+
26+
@Override
27+
public void debit(Double amount) {
28+
// TODO: Implement debit method
29+
// Investment accounts do NOT have overdraft protection - allow balance to go negative
30+
}
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.zipcoder;
2+
3+
public class Person {
4+
private String firstName;
5+
private String lastName;
6+
private String email;
7+
private String phoneNumber;
8+
9+
public Person(String firstName, String lastName, String email, String phoneNumber) {
10+
// TODO: Implement constructor
11+
}
12+
13+
public String getFirstName() {
14+
// TODO: Implement getter
15+
return null;
16+
}
17+
18+
public void setFirstName(String firstName) {
19+
// TODO: Implement setter
20+
}
21+
22+
public String getLastName() {
23+
// TODO: Implement getter
24+
return null;
25+
}
26+
27+
public void setLastName(String lastName) {
28+
// TODO: Implement setter
29+
}
30+
31+
public String getEmail() {
32+
// TODO: Implement getter
33+
return null;
34+
}
35+
36+
public void setEmail(String email) {
37+
// TODO: Implement setter
38+
}
39+
40+
public String getPhoneNumber() {
41+
// TODO: Implement getter
42+
return null;
43+
}
44+
45+
public void setPhoneNumber(String phoneNumber) {
46+
// TODO: Implement setter
47+
}
48+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.zipcoder;
2+
3+
public class SavingsAccount extends Account {
4+
private Double interestRate;
5+
6+
public SavingsAccount(Object accountHolder, Double balance, String accountNumber, Double interestRate) {
7+
super(accountHolder, balance, accountNumber);
8+
// TODO: Implement constructor
9+
}
10+
11+
public Double getInterestRate() {
12+
// TODO: Implement getter
13+
return null;
14+
}
15+
16+
public void setInterestRate(Double interestRate) {
17+
// TODO: Implement setter
18+
}
19+
20+
public void applyInterest() {
21+
// TODO: Implement method to apply interest to the balance
22+
// New balance = current balance + (current balance * interest rate)
23+
}
24+
25+
@Override
26+
public void debit(Double amount) {
27+
// TODO: Implement debit method
28+
// Savings accounts have overdraft protection - don't allow balance to go negative
29+
}
30+
}

0 commit comments

Comments
 (0)