-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountTest.java
More file actions
90 lines (77 loc) · 2.86 KB
/
Copy pathAccountTest.java
File metadata and controls
90 lines (77 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.bank.model;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
class AccountTest {
private SavingsAccount savingsAccount;
private CheckingAccount checkingAccount;
@BeforeEach
void setUp() {
savingsAccount = new SavingsAccount("John Doe", 1000.0);
checkingAccount = new CheckingAccount("Jane Smith", 500.0);
}
@Test
@DisplayName("Should create account with valid initial deposit")
void testAccountCreation() {
assertNotNull(savingsAccount.getAccountNumber());
assertEquals("John Doe", savingsAccount.getAccountHolderName());
assertEquals(1000.0, savingsAccount.getBalance());
assertTrue(savingsAccount.isActive());
}
@Test
@DisplayName("Should throw exception for empty account holder name")
void testEmptyAccountHolderName() {
assertThrows(IllegalArgumentException.class,
() -> new SavingsAccount("", 1000.0));
}
@Test
@DisplayName("Should deposit amount successfully")
void testDeposit() {
savingsAccount.deposit(500.0);
assertEquals(1500.0, savingsAccount.getBalance());
}
@Test
@DisplayName("Should throw exception for negative deposit")
void testNegativeDeposit() {
assertThrows(IllegalArgumentException.class,
() -> savingsAccount.deposit(-100.0));
}
@Test
@DisplayName("Should withdraw amount successfully")
void testWithdrawal() {
checkingAccount.withdraw(200.0);
assertEquals(300.0, checkingAccount.getBalance());
}
@Test
@DisplayName("Should throw exception for insufficient funds")
void testInsufficientFunds() {
assertThrows(InsufficientFundsException.class,
() -> savingsAccount.withdraw(2000.0));
}
@Test
@DisplayName("Should transfer amount between accounts")
void testTransfer() {
savingsAccount.transfer(checkingAccount, 300.0);
assertEquals(700.0, savingsAccount.getBalance());
assertEquals(800.0, checkingAccount.getBalance());
}
@Test
@DisplayName("Should maintain transaction history")
void testTransactionHistory() {
savingsAccount.deposit(200.0);
savingsAccount.withdraw(100.0);
assertEquals(3, savingsAccount.getTransactionHistory().size());
}
@Test
@DisplayName("Should enforce minimum balance for savings account")
void testSavingsMinimumBalance() {
assertThrows(InsufficientFundsException.class,
() -> savingsAccount.withdraw(600.0));
}
@Test
@DisplayName("Should close account with zero balance")
void testCloseAccount() {
CheckingAccount acc = new CheckingAccount("Test", 0);
acc.closeAccount();
assertFalse(acc.isActive());
}
}