Skip to content

Commit 9746c24

Browse files
author
AmiyahJo
committed
feat: adds BusinessCheckingAccount tests
fix: businesscheckingAccount parameters fixed changed from 0.0 to just initialBalance
1 parent e8f7503 commit 9746c24

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
public class BusinessCheckingAccount extends CheckingAccount{
55
private final String businessName;
66

7-
public BusinessCheckingAccount(String accountNumber, Set<Customer> owners, String businessName) {
8-
super(accountNumber, owners, 0.0);
7+
public BusinessCheckingAccount(String accountNumber, Set<Customer> owners, String businessName, double initialBalance) {
8+
super(accountNumber, owners, initialBalance);
99
this.businessName = businessName;
1010
}
1111

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

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

3+
import java.util.Set;
4+
import java.util.UUID;
5+
36
import static org.assertj.core.api.Assertions.assertThat;
47
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
510

611
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
712
import com.codedifferently.lesson17.bank.exceptions.CheckVoidedException;
8-
import java.util.Set;
9-
import java.util.UUID;
10-
import org.junit.jupiter.api.BeforeEach;
11-
import org.junit.jupiter.api.Test;
1213

1314
class BankAtmTest {
1415

@@ -107,4 +108,38 @@ void testWithdrawFunds_AccountNotFound() {
107108
.isThrownBy(() -> classUnderTest.withdrawFunds(nonExistingAccountNumber, 50.0))
108109
.withMessage("Account not found");
109110
}
111+
112+
@Test
113+
void testAddBusinessCheckingAccountWithoutBusinessAccount() {
114+
// Arrange
115+
Customer businessOwner = new Customer(UUID.randomUUID(), "Business Owner");
116+
Set<Customer> owners = Set.of(businessOwner);
117+
BusinessCheckingAccount businessAccount = new BusinessCheckingAccount("123456789", owners, "Business Inc.", 1000.0);
118+
119+
// Act & Assert
120+
assertThatExceptionOfType(IllegalArgumentException.class)
121+
.isThrownBy(() -> classUnderTest.addAccount(businessAccount))
122+
.withMessage("At least one owning account must be a business account.");
123+
}
124+
125+
@Test
126+
void testAddBusinessCheckingAccountWithBusinessAccount() {
127+
// Arrange
128+
Customer businessOwner = new Customer(UUID.randomUUID(), "Business Owner");
129+
Set<Customer> owners = Set.of(businessOwner);
130+
131+
BusinessCheckingAccount existingBusinessAccount = new BusinessCheckingAccount("123456789", owners, "Existing Business", 1000.0);
132+
classUnderTest.addAccount(existingBusinessAccount);
133+
134+
135+
BusinessCheckingAccount newBusinessAccount = new BusinessCheckingAccount("789456123", owners, "New Business", 1000.0);
136+
137+
// Act
138+
classUnderTest.addAccount(newBusinessAccount);
139+
140+
// Assert
141+
Set<CheckingAccount> accounts = classUnderTest.findAccountsByCustomerId(businessOwner.getId());
142+
assertThat(accounts).contains(existingBusinessAccount, newBusinessAccount);
143+
}
144+
110145
}

0 commit comments

Comments
 (0)