Skip to content

Commit c70a225

Browse files
committed
feat: added Audit log and Savings Account class with test By Yemi
1 parent e8dbe17 commit c70a225

File tree

6 files changed

+35
-38
lines changed

6 files changed

+35
-38
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
*/
1313
public class AuditLog {
1414

15-
// Method to add a value to an existing ArrayList or create a new one if accountNumber doesn't exist
16-
public void addToMap(HashMap<String, ArrayList<Double>> accountNumberByValueLog, String accountNumber, Double value) {
17-
accountNumberByValueLog.computeIfAbsent(accountNumber, k -> new ArrayList<>()).add(value);
18-
}
19-
}
15+
// Method to add a value to an existing ArrayList or create a new one if accountNumber doesn't
16+
// exist
17+
public void addToMap(
18+
HashMap<String, ArrayList<Double>> accountNumberByValueLog,
19+
String accountNumber,
20+
Double value) {
21+
accountNumberByValueLog.computeIfAbsent(accountNumber, k -> new ArrayList<>()).add(value);
22+
}
23+
}

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

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

3+
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
34
import java.util.Set;
4-
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77

8-
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
9-
108
/** Represents a checking account. */
119
public class BankAccount {
1210

@@ -16,7 +14,6 @@ public class BankAccount {
1614
private boolean isActive;
1715
private static final Logger logger = LoggerFactory.getLogger(SavingAccount.class);
1816

19-
2017
/**
2118
* Creates a new checking account.
2219
*
@@ -82,7 +79,7 @@ public void withdraw(double amount) throws InsufficientFundsException {
8279
throw new IllegalStateException("Withdrawal amount must be positive");
8380
}
8481
if (balance < amount) {
85-
logger.info("Account does not have enough funds for withdrawal");
82+
logger.info("Account does not have enough funds for withdrawal");
8683
throw new InsufficientFundsException("Account does not have enough funds for withdrawal");
8784
}
8885
balance -= amount;
@@ -100,7 +97,7 @@ public double getBalance() {
10097
/** Closes the account. */
10198
public void closeAccount() throws IllegalStateException {
10299
if (balance > 0) {
103-
logger.info("Cannot close account with a positive balance");
100+
logger.info("Cannot close account with a positive balance");
104101
throw new IllegalStateException("Cannot close account with a positive balance");
105102
}
106103
isActive = false;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.codedifferently.lesson17.bank;
22

33
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
4-
54
import java.util.ArrayList;
65
import java.util.HashMap;
76
import java.util.Map;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import java.util.Set;
44

55
/** Represents a checking account. */
6-
public class CheckingAccount extends BankAccount{
6+
public class CheckingAccount extends BankAccount {
77

8-
//private boolean isActive;
8+
// private boolean isActive;
99

1010
/**
1111
* Creates a new checking account.
@@ -15,7 +15,7 @@ public class CheckingAccount extends BankAccount{
1515
* @param initialBalance The initial balance of the account.
1616
*/
1717
public CheckingAccount(String accountNumber, Set<Customer> owners, double balance) {
18-
super(accountNumber, owners, balance);
19-
//isActive = true;
18+
super(accountNumber, owners, balance);
19+
// isActive = true;
2020
}
2121
}
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.codedifferently.lesson17.bank;
22

3-
43
import java.util.Set;
5-
64
import org.slf4j.Logger;
75
import org.slf4j.LoggerFactory;
86

97
/** Represents a saving account. */
10-
public class SavingAccount extends BankAccount{
11-
//private boolean isActive;
12-
private boolean isCheckCreationAllowed;
13-
private static final Logger logger = LoggerFactory.getLogger(SavingAccount.class);
8+
public class SavingAccount extends BankAccount {
9+
// private boolean isActive;
10+
private boolean isCheckCreationAllowed;
11+
private static final Logger logger = LoggerFactory.getLogger(SavingAccount.class);
1412

1513
/**
1614
* Creates a new saving account.
@@ -20,13 +18,12 @@ public class SavingAccount extends BankAccount{
2018
* @param initialBalance The initial balance of the account.
2119
*/
2220
public SavingAccount(String accountNumber, Set<Customer> owners, double balance) {
23-
super(accountNumber, owners, balance);
21+
super(accountNumber, owners, balance);
2422
logger.info("Saving Account constructor accessed...");
2523
isCheckCreationAllowed = false;
2624
}
2725

2826
public boolean isCheckCreationAllowed() {
29-
return isCheckCreationAllowed;
27+
return isCheckCreationAllowed;
3028
}
31-
3229
}

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

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

3-
import java.util.HashSet;
4-
import java.util.Set;
5-
import java.util.UUID;
6-
73
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
84
import static org.junit.jupiter.api.Assertions.assertEquals;
95
import static org.junit.jupiter.api.Assertions.assertFalse;
106
import static org.junit.jupiter.api.Assertions.assertTrue;
11-
import org.junit.jupiter.api.BeforeEach;
12-
import org.junit.jupiter.api.Test;
137

148
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
9+
import java.util.HashSet;
10+
import java.util.Set;
11+
import java.util.UUID;
12+
import org.junit.jupiter.api.BeforeEach;
13+
import org.junit.jupiter.api.Test;
1514

1615
class SavingAccountTest {
1716

@@ -106,13 +105,14 @@ void toStringTest() {
106105
}
107106

108107
@Test
109-
public void testIsCheckCreationAllowed_WhenFalse() {
110-
// Arrange:
108+
public void testIsCheckCreationAllowed_WhenFalse() {
109+
// Arrange:
111110

112-
// Act:
113-
boolean result = classUnderTest.isCheckCreationAllowed();
111+
// Act:
112+
boolean result = classUnderTest.isCheckCreationAllowed();
114113

115-
// Assert:
116-
assertFalse(result, "Check creation should not be allowed when isCheckCreationAllowed is false");
117-
}
114+
// Assert:
115+
assertFalse(
116+
result, "Check creation should not be allowed when isCheckCreationAllowed is false");
117+
}
118118
}

0 commit comments

Comments
 (0)