|
1 | 1 | package com.codedifferently.lesson17.bank;
|
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
4 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
5 |
| -import static org.junit.jupiter.api.Assertions.assertFalse; |
6 |
| -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 4 | +import static org.junit.jupiter.api.Assertions.*; |
7 | 5 |
|
8 |
| -import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException; |
9 | 6 | import java.util.HashSet;
|
10 | 7 | import java.util.Set;
|
11 | 8 | import java.util.UUID;
|
12 | 9 | import org.junit.jupiter.api.BeforeEach;
|
13 | 10 | import org.junit.jupiter.api.Test;
|
14 | 11 |
|
15 | 12 | public class BusinessCheckingAccountTest {
|
16 |
| - |
17 |
| - private CheckingAccount classUnderTest; |
| 13 | + |
18 | 14 | private Set<Customer> owners;
|
19 | 15 |
|
20 | 16 | @BeforeEach
|
21 | 17 | void setUp() {
|
22 | 18 | owners = new HashSet<>();
|
23 | 19 | owners.add(new Customer(UUID.randomUUID(), "John Doe", false));
|
24 | 20 | owners.add(new Customer(UUID.randomUUID(), "Jane Smith", false));
|
25 |
| - classUnderTest = new BusinessCheckingAccount("123456789", owners, 100.0); |
26 |
| - } |
27 |
| - |
28 |
| - @Test |
29 |
| - void getAccountNumber() { |
30 |
| - assertEquals("123456789", classUnderTest.getAccountNumber()); |
| 21 | + new BusinessCheckingAccount("123456789", owners, 100.0); |
31 | 22 | }
|
32 | 23 |
|
33 | 24 | @Test
|
34 |
| - void getOwners() { |
35 |
| - assertEquals(owners, classUnderTest.getOwners()); |
36 |
| - } |
37 |
| - |
38 |
| - @Test |
39 |
| - void deposit() { |
40 |
| - classUnderTest.deposit(50.0); |
41 |
| - assertEquals(150.0, classUnderTest.getBalance()); |
42 |
| - } |
| 25 | + void businessCheckingAccount_withNoBusinessOwner_shouldThrowException() { |
| 26 | + Set<Customer> owners = new HashSet<>(); |
| 27 | + owners.add(new Customer(UUID.randomUUID(), "Individual Owner", false)); |
43 | 28 |
|
44 |
| - @Test |
45 |
| - void deposit_withNegativeAmount() { |
46 | 29 | assertThatExceptionOfType(IllegalArgumentException.class)
|
47 |
| - .isThrownBy(() -> classUnderTest.deposit(-50.0)); |
48 |
| - } |
49 |
| - |
50 |
| - @Test |
51 |
| - void withdraw() { |
52 |
| - classUnderTest.withdraw(50.0); |
53 |
| - assertEquals(50.0, classUnderTest.getBalance()); |
54 |
| - } |
55 |
| - |
56 |
| - @Test |
57 |
| - void withdraw_withNegativeAmount() { |
58 |
| - assertThatExceptionOfType(IllegalStateException.class) |
59 |
| - .isThrownBy(() -> classUnderTest.withdraw(-50.0)) |
60 |
| - .withMessage("Withdrawal amount must be positive"); |
61 |
| - } |
62 |
| - |
63 |
| - @Test |
64 |
| - void withdraw_withInsufficientBalance() { |
65 |
| - assertThatExceptionOfType(InsufficientFundsException.class) |
66 |
| - .isThrownBy(() -> classUnderTest.withdraw(150.0)) |
67 |
| - .withMessage("Account does not have enough funds for withdrawal"); |
68 |
| - } |
69 |
| - |
70 |
| - @Test |
71 |
| - void getBalance() { |
72 |
| - assertEquals(100.0, classUnderTest.getBalance()); |
73 |
| - } |
74 |
| - |
75 |
| - @Test |
76 |
| - void closeAccount_withPositiveBalance() { |
77 |
| - assertThatExceptionOfType(IllegalStateException.class) |
78 |
| - .isThrownBy(() -> classUnderTest.closeAccount()); |
| 30 | + .isThrownBy(() -> new BusinessCheckingAccount("123456789", owners, 100.0)) |
| 31 | + .withMessage("At least one owner must be a business for a BusinessCheckingAccount"); |
79 | 32 | }
|
80 | 33 |
|
81 | 34 | @Test
|
82 |
| - void isClosed() { |
83 |
| - assertFalse(classUnderTest.isClosed()); |
84 |
| - classUnderTest.withdraw(100); |
85 |
| - classUnderTest.closeAccount(); |
86 |
| - assertTrue(classUnderTest.isClosed()); |
87 |
| - } |
88 |
| - |
89 |
| - @Test |
90 |
| - void equals() { |
91 |
| - BusinessCheckingAccount otherAccount = new BusinessCheckingAccount("123456789", owners, 200.0); |
92 |
| - assertEquals(classUnderTest, otherAccount); |
93 |
| - } |
| 35 | + void businessCheckingAccount_withBusinessOwner_shouldCreateAccount() { |
| 36 | + Set<Customer> owners = new HashSet<>(); |
| 37 | + owners.add(new Customer(UUID.randomUUID(), "Business Owner", true)); |
94 | 38 |
|
95 |
| - @Test |
96 |
| - void hashCodeTest() { |
97 |
| - BusinessCheckingAccount otherAccount = new BusinessCheckingAccount("123456789", owners, 200.0); |
98 |
| - assertEquals(classUnderTest.hashCode(), otherAccount.hashCode()); |
99 |
| - } |
100 |
| - |
101 |
| - @Test |
102 |
| - void toStringTest() { |
103 |
| - String expected = "BusinessCheckingAccount{accountNumber='123456789', balance=100.0, isActive=true}"; |
104 |
| - assertEquals(expected, classUnderTest.toString()); |
| 39 | + BusinessCheckingAccount account = new BusinessCheckingAccount("123456789", owners, 100.0); |
| 40 | + assertEquals("123456789", account.getAccountNumber()); |
105 | 41 | }
|
106 | 42 | }
|
0 commit comments