|
1 | 1 | package com.codedifferently.lesson17.bank;
|
2 | 2 |
|
| 3 | +import java.util.Set; |
| 4 | +import java.util.UUID; |
| 5 | + |
3 | 6 | import static org.assertj.core.api.Assertions.assertThat;
|
4 | 7 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
| 8 | +import org.junit.jupiter.api.BeforeEach; |
| 9 | +import org.junit.jupiter.api.Test; |
5 | 10 |
|
6 | 11 | import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
|
7 | 12 | 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; |
12 | 13 |
|
13 | 14 | class BankAtmTest {
|
14 | 15 |
|
@@ -107,4 +108,38 @@ void testWithdrawFunds_AccountNotFound() {
|
107 | 108 | .isThrownBy(() -> classUnderTest.withdrawFunds(nonExistingAccountNumber, 50.0))
|
108 | 109 | .withMessage("Account not found");
|
109 | 110 | }
|
| 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 | + |
110 | 145 | }
|
0 commit comments