Skip to content

Commit 031c6d3

Browse files
committed
feat:changes
1 parent 0e59b01 commit 031c6d3

File tree

6 files changed

+18
-46
lines changed

6 files changed

+18
-46
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55

66
package com.codedifferently.lesson17.bank;
77

8-
import java.util.Set;
9-
108
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
9+
import java.util.Set;
1110

1211
/**
13-
*
1412
* @author vscode
1513
*/
1614
public abstract class Account {
1715

18-
protected final Set<Customer> owners;
19-
protected final String accountNumber;
20-
protected double balance;
21-
protected boolean isActive;
16+
protected final Set<Customer> owners;
17+
protected final String accountNumber;
18+
protected double balance;
19+
protected boolean isActive;
2220

2321
/**
2422
* Creates a new checking account.
@@ -137,5 +135,4 @@ public String toString() {
137135
+ isActive
138136
+ '}';
139137
}
140-
141138
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ public Set<CheckingAccount> findAccountsByCustomerId(UUID customerId) {
4747
* @param accountNumber The account number.
4848
* @param amount The amount to deposit.
4949
*/
50-
public String depositFunds(String accountNumber, double amount) {
50+
public void depositFunds(String accountNumber, double amount) {
5151
CheckingAccount account = getAccountOrThrow(accountNumber);
5252
account.deposit(amount);
5353
atmLog.addLog(
5454
new AuditLogInfo(TranscationType.DEPOSIT, amount, account.getBalance(), accountNumber));
55-
return atmLog.showLog();
5655
}
5756

5857
/**
@@ -61,12 +60,12 @@ public String depositFunds(String accountNumber, double amount) {
6160
* @param accountNumber The account number.
6261
* @param check The check to deposit.
6362
*/
64-
public void depositFunds(String accountNumber, Check check) {
63+
public void depositFunds(String accountNumber, FundTransfer fundTransfer) {
6564
CheckingAccount account = getAccountOrThrow(accountNumber);
66-
check.depositFunds(account);
65+
fundTransfer.depositFunds(account);
6766
atmLog.addLog(
6867
new AuditLogInfo(
69-
TranscationType.DEPOSIT, check.amount, account.getBalance(), accountNumber));
68+
TranscationType.DEPOSIT, fundTransfer.amount, account.getBalance(), accountNumber));
7069
}
7170

7271
/**
@@ -75,12 +74,11 @@ public void depositFunds(String accountNumber, Check check) {
7574
* @param accountNumber
7675
* @param amount
7776
*/
78-
public String withdrawFunds(String accountNumber, double amount) {
77+
public void withdrawFunds(String accountNumber, double amount) {
7978
CheckingAccount account = getAccountOrThrow(accountNumber);
8079
account.withdraw(amount);
8180
atmLog.addLog(
8281
new AuditLogInfo(TranscationType.WITHDRAWAL, -amount, account.getBalance(), accountNumber));
83-
return atmLog.showLog();
8482
}
8583

8684
/**

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

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

3-
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
43
import java.util.Set;
54

65
/** Represents a checking account. */
76
public class CheckingAccount extends Account {
87

9-
10-
118
/**
129
* Creates a new checking account.
1310
*
@@ -24,4 +21,4 @@ public CheckingAccount(String accountNumber, Set<Customer> owners, double initia
2421
*
2522
* @return The account number.
2623
*/
27-
}
24+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ public class MoneyOrder extends FundTransfer {
1414

1515
public MoneyOrder(
1616
String moneyOrderID, double amount, CheckingAccount account, CheckingAccount toAccount) {
17-
super(moneyOrderID, amount, account);
18-
depositFunds(toAccount);
17+
super(moneyOrderID, amount, account);
18+
this.toAccount = toAccount;
19+
depositFunds(toAccount);
1920
}
21+
22+
23+
2024
}

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void testDepositFunds_Check() {
7878
assertThat(account2.getBalance()).isEqualTo(300.0);
7979
}
8080

81+
8182
@Test
8283
void testDepositFunds_DoesntDepositCheckTwice() {
8384
Check check = new Check("987654321", 100.0, account1);
@@ -107,26 +108,4 @@ void testWithdrawFunds_AccountNotFound() {
107108
.isThrownBy(() -> classUnderTest.withdrawFunds(nonExistingAccountNumber, 50.0))
108109
.withMessage("Account not found");
109110
}
110-
111-
@Test
112-
void testDepositFunds_auditLogIsCorrect() {
113-
// When
114-
String actual = classUnderTest.depositFunds("123456789", 50);
115-
String expected = "123456789 DEPOSIT 50.0 150.0";
116-
assertThat(actual.equals(expected));
117-
}
118-
119-
@Test
120-
void testDepositFunds_auditLogIsCorrectWithMultipleDebitsAndCredits() {
121-
122-
Check check = new Check("987654321", 100.0, account1);
123-
// When
124-
classUnderTest.depositFunds("123456789", 50);
125-
classUnderTest.depositFunds("987654321", 150);
126-
classUnderTest.depositFunds("123456789", check);
127-
String actual = classUnderTest.withdrawFunds("123456789", 35.0);
128-
String expected =
129-
"123456789 DEPOSIT 50.0 150.0 \n 987654321 DEPOSIT 150.0 350.0 \n 123456789 DEPOSIT 100.0 450.0 \n 123456789 WITHDRAWAL -35.0 415";
130-
assertThat(actual.equals(expected));
131-
}
132111
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,4 @@ void testConstructor_CantCreateMoneyOrderWithNegativeAmount() {
4646
.isThrownBy(() -> new MoneyOrder("123456789", -50.0, account1, account2))
4747
.withMessage("Cannot transfer negative amount");
4848
}
49-
50-
51-
5249
}

0 commit comments

Comments
 (0)