Skip to content

Commit fc14063

Browse files
committed
fiji
1 parent 5442e18 commit fc14063

File tree

7 files changed

+42
-50
lines changed

7 files changed

+42
-50
lines changed

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/BankAtm.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.codedifferently.lesson17.bank;
22

3+
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
34
import java.util.HashMap;
45
import java.util.Map;
56
import java.util.Set;
67
import java.util.UUID;
78

8-
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
9-
109
/**
1110
* Represents a bank ATM with support for multiple account types and comprehensive audit logging.
1211
* Enhanced to follow SOLID principles.
@@ -87,7 +86,9 @@ public void depositFunds(String accountNumber, Check check) {
8786

8887
// Only checking accounts can accept check deposits
8988
if (!(account instanceof CheckingAccount)) {
90-
throw new IllegalArgumentException("Cannot deposit checks to savings accounts. Account type: " + account.getClass().getSimpleName());
89+
throw new IllegalArgumentException(
90+
"Cannot deposit checks to savings accounts. Account type: "
91+
+ account.getClass().getSimpleName());
9192
}
9293

9394
CheckingAccount checkingAccount = (CheckingAccount) account;

lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/BankAtmIntegrationTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
import static org.junit.jupiter.api.Assertions.assertThrows;
77
import static org.junit.jupiter.api.Assertions.assertTrue;
88

9+
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
10+
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
911
import java.util.List;
1012
import java.util.Set;
1113
import java.util.UUID;
12-
1314
import org.junit.jupiter.api.BeforeEach;
1415
import org.junit.jupiter.api.Test;
1516

16-
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
17-
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
18-
1917
/** Integration tests for BankAtm with SavingsAccount and AuditLog. */
2018
class BankAtmIntegrationTest {
2119

@@ -92,11 +90,12 @@ void testSavingsAccountCannotAcceptCheckDeposits() {
9290

9391
// This should throw an exception - depositing check to savings account
9492
Check savingsCheck = new Check("C002", 50.0, checkingAccount);
95-
IllegalArgumentException exception = assertThrows(
96-
IllegalArgumentException.class,
97-
() -> bankAtm.depositFunds("SAV001", savingsCheck),
98-
"Should not allow check deposits to savings accounts");
99-
93+
IllegalArgumentException exception =
94+
assertThrows(
95+
IllegalArgumentException.class,
96+
() -> bankAtm.depositFunds("SAV001", savingsCheck),
97+
"Should not allow check deposits to savings accounts");
98+
10099
assertThat(exception.getMessage())
101100
.isEqualTo("Cannot deposit checks to savings accounts. Account type: SavingsAccount");
102101
}

lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/BankAtmTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
55

6+
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
7+
import com.codedifferently.lesson17.bank.exceptions.CheckVoidedException;
68
import java.util.Set;
79
import java.util.UUID;
8-
910
import org.junit.jupiter.api.BeforeEach;
1011
import org.junit.jupiter.api.Test;
1112

12-
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
13-
import com.codedifferently.lesson17.bank.exceptions.CheckVoidedException;
14-
1513
class BankAtmTest {
1614

1715
private BankAtm classUnderTest;
@@ -162,7 +160,7 @@ void testDepositCheckToSavingsAccountThrowsException() {
162160
SavingsAccount savingsAccount = new SavingsAccount("SAV001", Set.of(customer3), 500.0);
163161
customer3.addAccount(savingsAccount);
164162
classUnderTest.addAccount(savingsAccount);
165-
163+
166164
Check check = new Check("CHK001", 50.0, account1);
167165

168166
// Act & Assert

lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/BaseAccountTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
55

6+
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
67
import java.util.Set;
78
import java.util.UUID;
8-
99
import org.junit.jupiter.api.BeforeEach;
1010
import org.junit.jupiter.api.Test;
1111

12-
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
13-
1412
class BaseAccountTest {
1513

1614
private CheckingAccount account; // Using CheckingAccount as concrete implementation

lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/CheckingAccountTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
import static org.junit.jupiter.api.Assertions.assertFalse;
66
import static org.junit.jupiter.api.Assertions.assertTrue;
77

8+
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
89
import java.util.HashSet;
910
import java.util.Set;
1011
import java.util.UUID;
11-
1212
import org.junit.jupiter.api.BeforeEach;
1313
import org.junit.jupiter.api.Test;
1414

15-
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
16-
1715
class CheckingAccountTest {
1816

1917
private CheckingAccount classUnderTest;

lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/CustomerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import java.util.Set;
66
import java.util.UUID;
7-
87
import org.junit.jupiter.api.BeforeEach;
98
import org.junit.jupiter.api.Test;
109

lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/PolymorphicAccountTest.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import java.util.Set;
66
import java.util.UUID;
7-
87
import org.junit.jupiter.api.BeforeEach;
98
import org.junit.jupiter.api.Test;
109

@@ -19,13 +18,13 @@ class PolymorphicAccountTest {
1918
void setUp() {
2019
bankAtm = new BankAtm();
2120
customer = new Customer(UUID.randomUUID(), "John Doe");
22-
21+
2322
checkingAccount = new CheckingAccount("CHK001", Set.of(customer), 1000.0);
2423
savingsAccount = new SavingsAccount("SAV001", Set.of(customer), 500.0);
25-
24+
2625
customer.addAccount(checkingAccount);
2726
customer.addAccount(savingsAccount);
28-
27+
2928
bankAtm.addAccount(checkingAccount);
3029
bankAtm.addAccount(savingsAccount);
3130
}
@@ -38,7 +37,7 @@ void testFindAccountsByCustomerIdReturnsPolymorphicAccounts() {
3837
// Assert - Should return both checking and savings accounts as Account interface
3938
assertThat(accounts).hasSize(2);
4039
assertThat(accounts).containsExactlyInAnyOrder(checkingAccount, savingsAccount);
41-
40+
4241
// Verify they are polymorphic - can be treated as Account interface
4342
for (Account account : accounts) {
4443
assertThat(account.getAccountNumber()).isNotEmpty();
@@ -51,26 +50,28 @@ void testFindAccountsByCustomerIdReturnsPolymorphicAccounts() {
5150
void testPolymorphicAccountOperations() {
5251
// Get accounts polymorphically
5352
Set<Account> accounts = bankAtm.findAccountsByCustomerId(customer.getId());
54-
53+
5554
// Find savings account polymorphically
56-
Account savingsAsAccount = accounts.stream()
57-
.filter(acc -> acc.getAccountNumber().equals("SAV001"))
58-
.findFirst()
59-
.orElseThrow();
60-
61-
// Find checking account polymorphically
62-
Account checkingAsAccount = accounts.stream()
63-
.filter(acc -> acc.getAccountNumber().equals("CHK001"))
64-
.findFirst()
65-
.orElseThrow();
66-
55+
Account savingsAsAccount =
56+
accounts.stream()
57+
.filter(acc -> acc.getAccountNumber().equals("SAV001"))
58+
.findFirst()
59+
.orElseThrow();
60+
61+
// Find checking account polymorphically
62+
Account checkingAsAccount =
63+
accounts.stream()
64+
.filter(acc -> acc.getAccountNumber().equals("CHK001"))
65+
.findFirst()
66+
.orElseThrow();
67+
6768
// Both can be operated on through Account interface
6869
double initialSavingsBalance = savingsAsAccount.getBalance();
6970
double initialCheckingBalance = checkingAsAccount.getBalance();
70-
71+
7172
savingsAsAccount.deposit(100.0);
7273
checkingAsAccount.deposit(200.0);
73-
74+
7475
assertThat(savingsAsAccount.getBalance()).isEqualTo(initialSavingsBalance + 100.0);
7576
assertThat(checkingAsAccount.getBalance()).isEqualTo(initialCheckingBalance + 200.0);
7677
}
@@ -79,14 +80,12 @@ void testPolymorphicAccountOperations() {
7980
void testCustomerCanHoldMultipleAccountTypes() {
8081
// Verify customer can hold both account types
8182
Set<Account> customerAccounts = customer.getAccounts();
82-
83+
8384
assertThat(customerAccounts).hasSize(2);
84-
85-
boolean hasChecking = customerAccounts.stream()
86-
.anyMatch(acc -> acc instanceof CheckingAccount);
87-
boolean hasSavings = customerAccounts.stream()
88-
.anyMatch(acc -> acc instanceof SavingsAccount);
89-
85+
86+
boolean hasChecking = customerAccounts.stream().anyMatch(acc -> acc instanceof CheckingAccount);
87+
boolean hasSavings = customerAccounts.stream().anyMatch(acc -> acc instanceof SavingsAccount);
88+
9089
assertThat(hasChecking).isTrue();
9190
assertThat(hasSavings).isTrue();
9291
}

0 commit comments

Comments
 (0)