1
1
package com .codedifferently .lesson17 .bank ;
2
2
3
- import java .util .HashSet ;
4
- import java .util .Set ;
5
- import java .util .UUID ;
6
-
7
3
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
8
4
import static org .junit .jupiter .api .Assertions .assertEquals ;
9
5
import static org .junit .jupiter .api .Assertions .assertFalse ;
10
6
import static org .junit .jupiter .api .Assertions .assertTrue ;
7
+
8
+ import java .util .HashSet ;
9
+ import java .util .Set ;
10
+ import java .util .UUID ;
11
+
11
12
import org .junit .jupiter .api .BeforeEach ;
12
13
import org .junit .jupiter .api .Test ;
13
14
@@ -36,6 +37,11 @@ void getOwners() {
36
37
assertEquals (owners , classUnderTest .getOwners ());
37
38
}
38
39
40
+ @ Test
41
+ void initialBalanceIsCorrect () {
42
+ assertEquals (100.0 , classUnderTest .getBalance (), "Initial balance should be set correctly" );
43
+ }
44
+
39
45
@ Test
40
46
void deposit () {
41
47
classUnderTest .deposit (50.0 );
@@ -46,6 +52,7 @@ void deposit() {
46
52
void deposit_withNegativeAmount () {
47
53
assertThatExceptionOfType (IllegalArgumentException .class )
48
54
.isThrownBy (() -> classUnderTest .deposit (-50.0 ));
55
+ .withMessage ("Deposit amount must be positive" );
49
56
}
50
57
51
58
@ Test
@@ -56,7 +63,7 @@ void withdraw() {
56
63
57
64
@ Test
58
65
void withdraw_withNegativeAmount () {
59
- assertThatExceptionOfType (IllegalStateException .class )
66
+ assertThatExceptionOfType (IllegalArgumentException .class )
60
67
.isThrownBy (() -> classUnderTest .withdraw (-50.0 ))
61
68
.withMessage ("Withdrawal amount must be positive" );
62
69
}
@@ -76,7 +83,8 @@ void getBalance() {
76
83
@ Test
77
84
void closeAccount_withPositiveBalance () {
78
85
assertThatExceptionOfType (IllegalStateException .class )
79
- .isThrownBy (() -> classUnderTest .closeAccount ());
86
+ .isThrownBy (() -> classUnderTest .closeAccount ())
87
+ .withMessage ("Cannot close account with positive balance" );
80
88
}
81
89
82
90
@ Test
@@ -89,13 +97,13 @@ void isClosed() {
89
97
90
98
@ Test
91
99
void equals () {
92
- CheckingAccount otherAccount = new SavingsAccount ("123456789" , owners , 200.0 );
100
+ SavingsAccount otherAccount = new SavingsAccount ("123456789" , owners , 200.0 );
93
101
assertEquals (classUnderTest , otherAccount );
94
102
}
95
103
96
104
@ Test
97
105
void hashCodeTest () {
98
- CheckingAccount otherAccount = new SavingsAccount ("123456789" , owners , 200.0 );
106
+ SavingsAccount otherAccount = new SavingsAccount ("123456789" , owners , 200.0 );
99
107
assertEquals (classUnderTest .hashCode (), otherAccount .hashCode ());
100
108
}
101
109
0 commit comments