|
| 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 |
0 commit comments