Skip to content

Commit 7d5637e

Browse files
committed
adds validateBusinessOwners method
adds BusinessCheckingAccount Tests
1 parent 4de921f commit 7d5637e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ public BusinessCheckingAccount(
1717
super(accountNumber, owners, initialBalance);
1818
}
1919

20+
/**
21+
* Checks if at least one owner is a business.
22+
*
23+
* @param owners The owers of the account.
24+
* @throws IllegalArgumentEception If no business owner is found.
25+
*/
26+
private void validateBusinessOwner(Set<Customer> owners) {
27+
boolean hasBusinessOwner = owners.stream().anyMatch(Customer::isBusiness);
28+
if (!hasBusinessOwner) {
29+
throw new IllegalArgumentException(
30+
"Business Checking Account must have at least one business owner");
31+
}
32+
}
33+
2034
@Override
2135
public String toString() {
2236
return "BusinessCheckingAccount{"

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public Set<Account> getAccounts() {
6060
return accounts;
6161
}
6262

63+
/**
64+
* Checks if the owner is a business.
65+
*
66+
* @return True if the customer is a business, false otherwise.
67+
*/
68+
public boolean isBusiness() {
69+
return this.type == CustomerType.BUSINESS;
70+
}
71+
6372
@Override
6473
public int hashCode() {
6574
return id.hashCode();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.HashSet;
6+
import java.util.Set;
7+
import java.util.UUID;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
public class BusinessCheckingAccountTest {
12+
13+
@Test
14+
void validateBusinessOwner_withBusinessOwner() {
15+
Set<Customer> owners = new HashSet<>();
16+
owners.add(new Customer(UUID.randomUUID(), "Elon Musk", CustomerType.BUSINESS));
17+
owners.add(new Customer(UUID.randomUUID(), "Elon Musk", CustomerType.BUSINESS));
18+
19+
BusinessCheckingAccount account = new BusinessCheckingAccount("123456789", owners, 1000.0);
20+
assertThat(account).isNotNull();
21+
}
22+
}

0 commit comments

Comments
 (0)