Skip to content

Commit 2a62bae

Browse files
author
AmiyahJo
committed
chore: spotless apply
1 parent 02c2bf6 commit 2a62bae

File tree

12 files changed

+190
-172
lines changed

12 files changed

+190
-172
lines changed
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.codedifferently.lesson17.bank;
22

33
public interface Account {
4-
void deposit(double account);
5-
void withdraw(double amount);
6-
double getBalance();
7-
String getAccountNumber();
4+
void deposit(double account);
5+
6+
void withdraw(double amount);
7+
8+
double getBalance();
9+
10+
String getAccountNumber();
811
}

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
import java.util.List;
55

66
public class AuditLog {
7-
private final List<String> logEntries;
8-
9-
public AuditLog() {
10-
logEntries = new ArrayList<>();
11-
}
7+
private final List<String> logEntries;
128

13-
public void logTransaction(String accountNumber, String message, double amount, String type) {
14-
String logEntry = String.format("Account: %s | Transaction: %s | Amount: %.2f | Type: %s", accountNumber, message, amount, type);
15-
logEntries.add(logEntry);
16-
System.out.println(logEntry);
17-
}
9+
public AuditLog() {
10+
logEntries = new ArrayList<>();
11+
}
1812

19-
public List<String> getLogEntries() {
20-
return logEntries;
21-
}
13+
public void logTransaction(String accountNumber, String message, double amount, String type) {
14+
String logEntry =
15+
String.format(
16+
"Account: %s | Transaction: %s | Amount: %.2f | Type: %s",
17+
accountNumber, message, amount, type);
18+
logEntries.add(logEntry);
19+
System.out.println(logEntry);
20+
}
21+
22+
public List<String> getLogEntries() {
23+
return logEntries;
24+
}
2225
}

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

Lines changed: 11 additions & 11 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
/** Represents a bank ATM. */
1110
public class BankAtm {
1211

@@ -21,14 +20,15 @@ public class BankAtm {
2120
*/
2221
public void addAccount(CheckingAccount account) {
2322
if (account instanceof BusinessCheckingAccount) {
24-
boolean hasBusinessAccount = account.getOwners().stream()
25-
.anyMatch(owner -> owner.isBusiness());
23+
boolean hasBusinessAccount =
24+
account.getOwners().stream().anyMatch(owner -> owner.isBusiness());
25+
26+
if (!hasBusinessAccount) {
27+
throw new IllegalArgumentException(
28+
"At least one owning account must be a business account.");
29+
}
30+
}
2631

27-
if(!hasBusinessAccount) {
28-
throw new IllegalArgumentException("At least one owning account must be a business account.");
29-
}
30-
}
31-
3232
accountByNumber.put(account.getAccountNumber(), account);
3333
account
3434
.getOwners()
@@ -38,7 +38,6 @@ public void addAccount(CheckingAccount account) {
3838
});
3939
}
4040

41-
4241
/**
4342
* Finds all accounts owned by a customer.
4443
*
@@ -72,7 +71,8 @@ public void depositFunds(String accountNumber, double amount) {
7271
public void depositFunds(String accountNumber, Check check) {
7372
CheckingAccount account = getAccountOrThrow(accountNumber);
7473
check.depositFunds(account);
75-
auditLog.logTransaction("Deposited check to account: " + accountNumber, check.getAmount(), "Check Deposit");
74+
auditLog.logTransaction(
75+
"Deposited check to account: " + accountNumber, check.getAmount(), "Check Deposit");
7676
}
7777

7878
/**
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package com.codedifferently.lesson17.bank;
2+
23
import java.util.Set;
34

4-
public class BusinessCheckingAccount extends CheckingAccount{
5-
private final String businessName;
5+
public class BusinessCheckingAccount extends CheckingAccount {
6+
private final String businessName;
67

7-
/**
8-
* Creates a new business checking account.
9-
*
10-
* @param accountNumber The account number.
11-
* @param owners The owners of the account.
12-
* @param businessName The name of the business.
13-
* @param initialBalance The initial balance of the account.
14-
* @throws IllegalArgumentException if no business owner is provided.
15-
*/
16-
public BusinessCheckingAccount(String accountNumber, Set<Customer> owners, String businessName, double initialBalance) {
17-
super(accountNumber, owners, initialBalance);
18-
this.businessName = businessName;
19-
}
8+
/**
9+
* Creates a new business checking account.
10+
*
11+
* @param accountNumber The account number.
12+
* @param owners The owners of the account.
13+
* @param businessName The name of the business.
14+
* @param initialBalance The initial balance of the account.
15+
* @throws IllegalArgumentException if no business owner is provided.
16+
*/
17+
public BusinessCheckingAccount(
18+
String accountNumber, Set<Customer> owners, String businessName, double initialBalance) {
19+
super(accountNumber, owners, initialBalance);
20+
this.businessName = businessName;
21+
}
2022

21-
public String getBusinessName() {
22-
return businessName;
23-
}
23+
public String getBusinessName() {
24+
return businessName;
25+
}
2426
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void depositFunds(CheckingAccount toAccount) {
5656

5757
public double getAmount() {
5858
return amount;
59-
}
59+
}
6060

6161
@Override
6262
public int hashCode() {
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
package com.codedifferently.lesson17.bank;
22

33
public class MoneyOrder {
4-
private final CheckingAccount sourceAccount;
5-
private final double amount;
6-
private AuditLog auditLog;
7-
8-
public MoneyOrder(CheckingAccount sourceAccount, double amount, AuditLog auditLog) {
9-
this.sourceAccount = sourceAccount;
10-
this.amount = amount;
11-
this.auditLog = auditLog;
4+
private final CheckingAccount sourceAccount;
5+
private final double amount;
6+
private AuditLog auditLog;
127

13-
sourceAccount.withdraw(amount);
14-
15-
auditLog.logTransaction(sourceAccount.getAccountNumber(), "MoneyOrder created", -amount, "MoneyOrder");
16-
}
8+
public MoneyOrder(CheckingAccount sourceAccount, double amount, AuditLog auditLog) {
9+
this.sourceAccount = sourceAccount;
10+
this.amount = amount;
11+
this.auditLog = auditLog;
1712

18-
public CheckingAccount getSourceAccount() {
19-
return sourceAccount;
20-
}
13+
sourceAccount.withdraw(amount);
2114

22-
public double getAmount() {
23-
return amount;
24-
}
15+
auditLog.logTransaction(
16+
sourceAccount.getAccountNumber(), "MoneyOrder created", -amount, "MoneyOrder");
17+
}
18+
19+
public CheckingAccount getSourceAccount() {
20+
return sourceAccount;
21+
}
22+
23+
public double getAmount() {
24+
return amount;
25+
}
2526
}
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package com.codedifferently.lesson17.bank;
22

3-
import java.util.Set;
4-
53
import com.codedifferently.lesson17.bank.exceptions.CheckNotAllowedException;
4+
import java.util.Set;
65

76
public class SavingsAccount extends CheckingAccount {
8-
public SavingsAccount(String accountNumber, Set<Customer> owners, double initialBalance) {
9-
super(accountNumber, owners, Math.max(initialBalance, 0));
10-
}
11-
12-
@Override
13-
public void deposit(double amount) {
14-
super.deposit(amount);
15-
}
7+
public SavingsAccount(String accountNumber, Set<Customer> owners, double initialBalance) {
8+
super(accountNumber, owners, Math.max(initialBalance, 0));
9+
}
10+
11+
@Override
12+
public void deposit(double amount) {
13+
super.deposit(amount);
14+
}
1615

17-
@Override
18-
public void withdraw(double amount) {
19-
super.withdraw(amount);
20-
}
16+
@Override
17+
public void withdraw(double amount) {
18+
super.withdraw(amount);
19+
}
2120

22-
public void writeCheck(double amount) {
21+
public void writeCheck(double amount) {
2322
throw new CheckNotAllowedException("Savings account cannot write checks");
24-
}
23+
}
2524
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.codedifferently.lesson17.bank.exceptions;
22

33
public class CheckNotAllowedException extends RuntimeException {
4-
public CheckNotAllowedException(String message) {
5-
super(message);
6-
}
4+
public CheckNotAllowedException(String message) {
5+
super(message);
6+
}
77
}

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

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

3-
import java.util.Set;
4-
import java.util.UUID;
5-
63
import static org.assertj.core.api.Assertions.assertThat;
74
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
85
import static org.junit.jupiter.api.Assertions.assertThrows;
9-
import org.junit.jupiter.api.BeforeEach;
10-
import org.junit.jupiter.api.Test;
116

127
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
138
import com.codedifferently.lesson17.bank.exceptions.CheckVoidedException;
9+
import java.util.Set;
10+
import java.util.UUID;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
1413

1514
class BankAtmTest {
1615

@@ -52,16 +51,21 @@ void testAddAccount() {
5251
@Test
5352
void testAddBusinessAccountWithNoBusinessOwner() {
5453
// Arrange
55-
Customer regularCustomer = new Customer(UUID.randomUUID(), "Bob's Bakery", false);
56-
CheckingAccount businessAccount = new BusinessCheckingAccount("666666666", Set.of(regularCustomer), "name", 500.0);
54+
Customer regularCustomer = new Customer(UUID.randomUUID(), "Bob's Bakery", false);
55+
CheckingAccount businessAccount =
56+
new BusinessCheckingAccount("666666666", Set.of(regularCustomer), "name", 500.0);
5757

5858
// Act & Assert
59-
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> {
60-
classUnderTest.addAccount(businessAccount);
61-
});
62-
63-
assertThat(thrown).hasMessageContaining("At least one owning account must be a business account.");
64-
}
59+
IllegalArgumentException thrown =
60+
assertThrows(
61+
IllegalArgumentException.class,
62+
() -> {
63+
classUnderTest.addAccount(businessAccount);
64+
});
65+
66+
assertThat(thrown)
67+
.hasMessageContaining("At least one owning account must be a business account.");
68+
}
6569

6670
@Test
6771
void testFindAccountsByCustomerId() {
@@ -124,15 +128,15 @@ void testWithdrawFunds_AccountNotFound() {
124128
.withMessage("Account not found");
125129
}
126130

127-
@Test
131+
@Test
128132
void testGetBusinessName() {
129133
// Arrange
130134
Customer businessOwner = new Customer(UUID.randomUUID(), "Business Owner", true);
131135
Set<Customer> owners = Set.of(businessOwner);
132-
BusinessCheckingAccount businessAccount = new BusinessCheckingAccount("123456789", owners, "Business Inc.", 1000.0);
136+
BusinessCheckingAccount businessAccount =
137+
new BusinessCheckingAccount("123456789", owners, "Business Inc.", 1000.0);
133138

134-
//Act & Assert
139+
// Act & Assert
135140
assertThat(businessAccount.getBusinessName());
136141
}
137-
138142
}

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

Lines changed: 5 additions & 6 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 CheckingAccountTest {
1716

0 commit comments

Comments
 (0)