Skip to content

Commit af06127

Browse files
author
AmiyahJo
committed
feat: adds savings account test
1 parent 24ed85b commit af06127

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.codedifferently.lesson17.bank.exceptions.CheckNotAllowedException;
8+
9+
public class SavingsAccountTest {
10+
@Test
11+
void testDeposit() {
12+
// Arrange
13+
SavingsAccount account = new SavingsAccount("12345678", null, 5.00);
14+
account.deposit(200);
15+
16+
// Assert
17+
assertEquals(205.00, account.getBalance());
18+
}
19+
20+
@Test
21+
void testWithdraw() {
22+
// Arrange
23+
SavingsAccount account = new SavingsAccount("12345678", null, 0.00);
24+
account.deposit(1000);
25+
26+
// Act
27+
account.withdraw(500);
28+
29+
// Assert
30+
assertEquals(500, account.getBalance());
31+
}
32+
33+
@Test
34+
void testWriteCheck() {
35+
// Arrange
36+
SavingsAccount account = new SavingsAccount("12345678", null, 1000.00);
37+
38+
// Act & Assert
39+
CheckNotAllowedException thrown = assertThrows(CheckNotAllowedException.class, () -> {
40+
account.writeCheck(100);
41+
});
42+
43+
// Assert
44+
assertEquals("Savings account cannot write checks", thrown.getMessage());
45+
46+
}
47+
}

0 commit comments

Comments
 (0)