Skip to content

Commit 6b5f89f

Browse files
committed
adds BusinessCheckingAccount Tests
1 parent 4de921f commit 6b5f89f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-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();

0 commit comments

Comments
 (0)