File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff 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 );
You can’t perform that action at this time.
0 commit comments