Skip to content

Commit 51b472e

Browse files
feat: 80% coverage
1 parent 04df44a commit 51b472e

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.codedifferently.lesson17.bank.exceptions.UnsupportedCurrencyException;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class CurrencyConverterTest {
9+
10+
@Test
11+
public void testIfCurrencyConvertsFromUSDToEUR() {
12+
13+
try {
14+
double convertedCurrency = CurrencyConverter.convert(100, "USD", "EUR");
15+
assertEquals(90.00, convertedCurrency);
16+
} catch (UnsupportedCurrencyException e) {
17+
// TODO Auto-generated catch block
18+
e.printStackTrace();
19+
}
20+
}
21+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertFalse;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
9+
import java.util.HashSet;
10+
import java.util.Set;
11+
import java.util.UUID;
12+
import org.junit.jupiter.api.BeforeEach;
13+
import org.junit.jupiter.api.Test;
14+
15+
class SavingsAccountTest {
16+
17+
private SavingsAccount classUnderTest;
18+
private Set<Customer> owners;
19+
20+
@BeforeEach
21+
void setUp() {
22+
owners = new HashSet<>();
23+
owners.add(new Customer(UUID.randomUUID(), "John Doe"));
24+
owners.add(new Customer(UUID.randomUUID(), "Jane Smith"));
25+
classUnderTest = new SavingsAccount("123456789", owners, 100.0);
26+
}
27+
28+
@Test
29+
void getAccountNumber() {
30+
assertEquals("123456789", classUnderTest.getAccountNumber());
31+
}
32+
33+
@Test
34+
void getOwners() {
35+
assertEquals(owners, classUnderTest.getOwners());
36+
}
37+
38+
@Test
39+
void deposit() {
40+
classUnderTest.deposit(50.0);
41+
assertEquals(150.0, classUnderTest.getBalance());
42+
}
43+
44+
@Test
45+
void deposit_withNegativeAmount() {
46+
assertThatExceptionOfType(IllegalArgumentException.class)
47+
.isThrownBy(() -> classUnderTest.deposit(-50.0));
48+
}
49+
50+
@Test
51+
void withdraw() {
52+
classUnderTest.withdraw(50.0);
53+
assertEquals(50.0, classUnderTest.getBalance());
54+
}
55+
56+
@Test
57+
void withdraw_withNegativeAmount() {
58+
assertThatExceptionOfType(IllegalStateException.class)
59+
.isThrownBy(() -> classUnderTest.withdraw(-50.0))
60+
.withMessage("Withdrawal amount must be positive");
61+
}
62+
63+
@Test
64+
void withdraw_withInsufficientBalance() {
65+
assertThatExceptionOfType(InsufficientFundsException.class)
66+
.isThrownBy(() -> classUnderTest.withdraw(150.0))
67+
.withMessage("Account does not have enough funds for withdrawal");
68+
}
69+
70+
@Test
71+
void getBalance() {
72+
assertEquals(100.0, classUnderTest.getBalance());
73+
}
74+
75+
@Test
76+
void closeAccount_withPositiveBalance() {
77+
assertThatExceptionOfType(IllegalStateException.class)
78+
.isThrownBy(() -> classUnderTest.closeAccount());
79+
}
80+
81+
@Test
82+
void isClosed() {
83+
assertFalse(classUnderTest.isClosed());
84+
classUnderTest.withdraw(100);
85+
classUnderTest.closeAccount();
86+
assertTrue(classUnderTest.isClosed());
87+
}
88+
89+
@Test
90+
void equals() {
91+
SavingsAccount otherAccount = new SavingsAccount("123456789", owners, 200.0);
92+
assertEquals(classUnderTest, otherAccount);
93+
}
94+
95+
@Test
96+
void hashCodeTest() {
97+
SavingsAccount otherAccount = new SavingsAccount("123456789", owners, 200.0);
98+
assertEquals(classUnderTest.hashCode(), otherAccount.hashCode());
99+
}
100+
101+
@Test
102+
void toStringTest() {
103+
String expected = "SavingsAccount{accountNumber='123456789', balance=100.0, isActive=true}";
104+
assertEquals(expected, classUnderTest.toString());
105+
}
106+
}

0 commit comments

Comments
 (0)