-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAccountTest.java
More file actions
71 lines (56 loc) · 2.14 KB
/
AccountTest.java
File metadata and controls
71 lines (56 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.cleanengine.coin.user.domain;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.*;
@DisplayName("계좌 단위테스트")
class AccountTest {
@DisplayName("계좌의 예수금을 5000만큼 증가시킨다.")
@Test
void increaseCash() {
// given
Account account = Account.of(1, 1000.0);
// when
account.increaseCash(5000.0);
// then
assertEquals(6000.0, account.getCash());
}
@DisplayName("계좌의 예수금을 0만큼 증가시키면 예외가 발생한다.")
@Test
void increaseZeroCash() {
// given
Account account = Account.of(1, 1000.0);
// when, then
assertThatThrownBy(() -> account.increaseCash(0.0))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Increase amount must be greater than zero.");
}
@DisplayName("계좌의 예수금을 5000만큼 감소시킨다.")
@Test
void decreaseCash() {
// given
Account account = Account.of(1, 6000.0);
// when, then
assertEquals(1000.0, account.decreaseCash(5000.0).getCash());
}
@DisplayName("계좌의 예수금을 0만큼 감소시키면 예외가 발생한다.")
@Test
void decreaseZeroCash() {
// given
Account account = Account.of(1, 6000.0);
// when, then
assertThatThrownBy(() -> account.decreaseCash(0.0))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Decrease amount must be greater than zero.");
}
@DisplayName("계좌의 예수금보다 많은 금액을 감소시키면 예외가 발생한다.")
@Test
void decreaseCashUnderRemainingCash() {
// given
Account account = Account.of(1, 1000.0);
// when, then
assertThatThrownBy(() -> account.decreaseCash(5000.0))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cannot decrease cash. Available cash: 1000.0, requested: 5000.0");
}
}