Skip to content

Commit 6446892

Browse files
author
AmiyahJo
committed
feat: adds testAddBusinessAccountWIthNoBusinessOwner
rm: businessCheckingAccount boolean (Its already throwing an exception in BankAtm addAccount)
1 parent d8ebfc0 commit 6446892

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ public class BusinessCheckingAccount extends CheckingAccount{
1616
public BusinessCheckingAccount(String accountNumber, Set<Customer> owners, String businessName, double initialBalance) {
1717
super(accountNumber, owners, initialBalance);
1818
this.businessName = businessName;
19-
20-
if (owners.stream().noneMatch(owner -> owner.isBusiness())) {
21-
throw new IllegalArgumentException("At least one owner must be a business.");
22-
}
2319
}
2420

2521
public String getBusinessName() {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import static org.assertj.core.api.Assertions.assertThat;
77
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
8+
import static org.junit.jupiter.api.Assertions.assertThrows;
89
import org.junit.jupiter.api.BeforeEach;
910
import org.junit.jupiter.api.Test;
1011

@@ -48,6 +49,20 @@ void testAddAccount() {
4849
assertThat(accounts).containsOnly(account3);
4950
}
5051

52+
@Test
53+
void testAddBusinessAccountWithNoBusinessOwner() {
54+
// Arrange
55+
Customer regularCustomer = new Customer(UUID.randomUUID(), "Bob's Bakery", false);
56+
CheckingAccount businessAccount = new BusinessCheckingAccount("666666666", Set.of(regularCustomer), "name", 500.0);
57+
58+
// 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+
}
65+
5166
@Test
5267
void testFindAccountsByCustomerId() {
5368
// Act

0 commit comments

Comments
 (0)