Skip to content

Commit 9a1f465

Browse files
author
AmiyahJo
committed
feat: adds savings account class and test implementations
made a new test `initialBalanceIsCorrect` to verify the balance when the account is made , modifies refrence code from checkings into savings , and included error messages for exception types
1 parent d4730b1 commit 9a1f465

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
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 java.util.Set;
4+
import java.util.function.BooleanSupplier;
5+
6+
public class SavingsAccount {
7+
8+
public SavingsAccount(String string, Set<Customer> owners, double d) {
9+
//TODO Auto-generated constructor stub
10+
}
11+
12+
public Object getAccountNumber() {
13+
// TODO Auto-generated method stub
14+
throw new UnsupportedOperationException("Unimplemented method 'getAccountNumber'");
15+
}
16+
17+
public Object getOwners() {
18+
// TODO Auto-generated method stub
19+
throw new UnsupportedOperationException("Unimplemented method 'getOwners'");
20+
}
21+
22+
public Double getBalance() {
23+
// TODO Auto-generated method stub
24+
throw new UnsupportedOperationException("Unimplemented method 'getBalance'");
25+
}
26+
27+
public void deposit(double d) {
28+
// TODO Auto-generated method stub
29+
throw new UnsupportedOperationException("Unimplemented method 'deposit'");
30+
}
31+
32+
public void withdraw(double d) {
33+
// TODO Auto-generated method stub
34+
throw new UnsupportedOperationException("Unimplemented method 'withdraw'");
35+
}
36+
37+
public Object closeAccount() {
38+
// TODO Auto-generated method stub
39+
throw new UnsupportedOperationException("Unimplemented method 'closeAccount'");
40+
}
41+
42+
public BooleanSupplier isClosed() {
43+
// TODO Auto-generated method stub
44+
throw new UnsupportedOperationException("Unimplemented method 'isClosed'");
45+
}
46+
47+
}

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.codedifferently.lesson17.bank;
22

3-
import java.util.HashSet;
4-
import java.util.Set;
5-
import java.util.UUID;
6-
73
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
84
import static org.junit.jupiter.api.Assertions.assertEquals;
95
import static org.junit.jupiter.api.Assertions.assertFalse;
106
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+
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Test;
1314

@@ -36,6 +37,11 @@ void getOwners() {
3637
assertEquals(owners, classUnderTest.getOwners());
3738
}
3839

40+
@Test
41+
void initialBalanceIsCorrect() {
42+
assertEquals(100.0, classUnderTest.getBalance(), "Initial balance should be set correctly");
43+
}
44+
3945
@Test
4046
void deposit() {
4147
classUnderTest.deposit(50.0);
@@ -46,6 +52,7 @@ void deposit() {
4652
void deposit_withNegativeAmount() {
4753
assertThatExceptionOfType(IllegalArgumentException.class)
4854
.isThrownBy(() -> classUnderTest.deposit(-50.0));
55+
.withMessage("Deposit amount must be positive");
4956
}
5057

5158
@Test
@@ -56,7 +63,7 @@ void withdraw() {
5663

5764
@Test
5865
void withdraw_withNegativeAmount() {
59-
assertThatExceptionOfType(IllegalStateException.class)
66+
assertThatExceptionOfType(IllegalArgumentException.class)
6067
.isThrownBy(() -> classUnderTest.withdraw(-50.0))
6168
.withMessage("Withdrawal amount must be positive");
6269
}
@@ -76,7 +83,8 @@ void getBalance() {
7683
@Test
7784
void closeAccount_withPositiveBalance() {
7885
assertThatExceptionOfType(IllegalStateException.class)
79-
.isThrownBy(() -> classUnderTest.closeAccount());
86+
.isThrownBy(() -> classUnderTest.closeAccount())
87+
.withMessage("Cannot close account with positive balance");
8088
}
8189

8290
@Test
@@ -89,13 +97,13 @@ void isClosed() {
8997

9098
@Test
9199
void equals() {
92-
CheckingAccount otherAccount = new SavingsAccount("123456789", owners, 200.0);
100+
SavingsAccount otherAccount = new SavingsAccount("123456789", owners, 200.0);
93101
assertEquals(classUnderTest, otherAccount);
94102
}
95103

96104
@Test
97105
void hashCodeTest() {
98-
CheckingAccount otherAccount = new SavingsAccount("123456789", owners, 200.0);
106+
SavingsAccount otherAccount = new SavingsAccount("123456789", owners, 200.0);
99107
assertEquals(classUnderTest.hashCode(), otherAccount.hashCode());
100108
}
101109

0 commit comments

Comments
 (0)