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