Skip to content

Commit 7f1e94f

Browse files
committed
feat: Initial commit of Lesson 17. Still WIP.
1 parent d46c282 commit 7f1e94f

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import java.util.Set;
4+
5+
public class BusinessCheckingAccount extends CheckingAccount {
6+
7+
/**
8+
* Creates a new BusinessCheckingAccount with the specified account number, owners, and initial balance.
9+
*
10+
* This constructor ensures that the account meets the minimum requirements for a business checking account,
11+
* including a minimum initial balance of $10,000 and at least one business owner in the provided set of owners.
12+
* If these requirements are not met, an {@link IllegalArgumentException} is thrown.
13+
*
14+
* @param accountNumber The unique identifier for the account.
15+
* @param owners A set of {@link Customer} objects representing the owners of the account.
16+
* @param initialBalance The initial balance of the account, which must be at least $10,000.
17+
* @throws IllegalArgumentException If the initial balance is less than $10,000 or if none of the owners
18+
* meet the criteria to be considered a business owner.
19+
*/
20+
public BusinessCheckingAccount(
21+
String accountNumber, Set<Customer> owners, double initialBalance) {
22+
super(accountNumber, owners, initialBalance);
23+
24+
// Business Account Logic
25+
if (initialBalance < 10000) {
26+
throw new IllegalArgumentException("Business accounts require a minimum balance of $10,000.");
27+
}
28+
if (!hasBusinessOwner(owners)) {
29+
throw new IllegalArgumentException(
30+
"A business checking account must have at least one business owner.");
31+
}
32+
}
33+
34+
/**
35+
* Checks if at least one owner of the account is a business.
36+
*
37+
* <p>This method examines each owner in the "owners" set and returns true if any owner's name
38+
* contains "INC" or "LLC" (case-insensitive), which are used as indicators of a business owning
39+
* the account.
40+
*
41+
* @param owners The set of account owners to check.
42+
* @return true if the account has at least one business owner; false otherwise.
43+
*/
44+
public boolean hasBusinessOwner(Set<Customer> owners) {
45+
return getOwners().stream()
46+
.anyMatch(
47+
owner ->
48+
owner.getName().toUpperCase().contains("INC")
49+
|| owner.getName().toUpperCase().contains("LLC"));
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
import java.util.UUID;
6+
7+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertNotNull;
10+
import org.junit.jupiter.api.BeforeEach;
11+
import org.junit.jupiter.api.Test;
12+
13+
public class BusinessCheckingAccountTest {
14+
private Set<Customer> owners;
15+
16+
@BeforeEach
17+
public void setUp() {
18+
owners = new HashSet<>();
19+
}
20+
21+
@Test
22+
public void testBusinessCheckingAccount_HasBusinessOwner_WithIncInName() {
23+
UUID id = UUID.randomUUID();
24+
Customer businesserOwner = new Customer(id, "Bob INC.");
25+
26+
owners.add(businesserOwner);
27+
28+
BusinessCheckingAccount account = new BusinessCheckingAccount("12345", owners, 15000);
29+
assertNotNull(account);
30+
assertEquals(15000, account.getBalance());
31+
assertEquals("12345", account.getAccountNumber());
32+
}
33+
34+
@Test
35+
public void testBusinessCheckingAccount_HasBusinessOwner_WithLlcInName() {
36+
UUID id = UUID.randomUUID();
37+
Customer businesserOwner = new Customer(id, "Bob LLC.");
38+
39+
owners.add(businesserOwner);
40+
41+
BusinessCheckingAccount account = new BusinessCheckingAccount("12345", owners, 15000);
42+
assertNotNull(account);
43+
assertEquals(15000, account.getBalance());
44+
assertEquals("12345", account.getAccountNumber());
45+
}
46+
47+
@Test
48+
public void testBusinessCheckingAccount_WithoutBusinessOwner() {
49+
UUID individualId = UUID.randomUUID();
50+
Customer individualOwner = new Customer(individualId, "John Doe"); // Example customer without business designation
51+
52+
owners.add(individualOwner); // Add the individual owner to the set
53+
54+
assertThatThrownBy(() -> {
55+
new BusinessCheckingAccount("12345", owners, 15000);
56+
})
57+
.isInstanceOf(IllegalArgumentException.class)
58+
.hasMessageContaining("A business checking account must have at least one business owner.");
59+
}
60+
61+
@Test
62+
public void testBusinessCheckingAccount_BelowMinimumBalance() {
63+
UUID businessId = UUID.randomUUID();
64+
Customer businessOwner = new Customer(businessId, "ABC LLC"); // Create a customer with a valid business name
65+
66+
owners.add(businessOwner); // Add the business owner to the set
67+
68+
assertThatThrownBy(() -> {
69+
new BusinessCheckingAccount("12345", owners, 5000); // Attempt to create with a balance below 10,000
70+
})
71+
.isInstanceOf(IllegalArgumentException.class)
72+
.hasMessageContaining("Business accounts require a minimum balance of $10,000.");
73+
}
74+
}

0 commit comments

Comments
 (0)