Skip to content

Commit 28ff279

Browse files
committed
test: adds Closed Account Tests to CheckingAccountTest.java
1 parent 36fc786 commit 28ff279

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,38 @@ void deposit_withNegativeAmount() {
4747
.isThrownBy(() -> classUnderTest.deposit(-50.0));
4848
}
4949

50+
@Test
51+
void deposit_toClosedAccount() {
52+
classUnderTest.withdraw(100.0);
53+
classUnderTest.closeAccount();
54+
55+
assertThatExceptionOfType(IllegalStateException.class)
56+
.isThrownBy(() -> classUnderTest.deposit(50.0))
57+
.withMessage("Cannot deposit to a closed account");
58+
}
59+
60+
@Test
61+
void withdraw_fromClosedAccount() {
62+
classUnderTest.withdraw(100.0);
63+
classUnderTest.closeAccount();
64+
65+
assertThatExceptionOfType(IllegalStateException.class)
66+
.isThrownBy(() -> classUnderTest.withdraw(50.0))
67+
.withMessage("Cannot withdraw from a closed account");
68+
}
69+
70+
@Test
71+
void closeAccount_successfullyClosesAccount() {
72+
// First withdraw all funds
73+
classUnderTest.withdraw(100.0);
74+
75+
// Act
76+
classUnderTest.closeAccount();
77+
78+
// Assert
79+
assertTrue(classUnderTest.isClosed());
80+
}
81+
5082
@Test
5183
void withdraw() {
5284
classUnderTest.withdraw(50.0);

0 commit comments

Comments
 (0)