-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWalletServiceTest.java
More file actions
95 lines (76 loc) · 3.13 KB
/
WalletServiceTest.java
File metadata and controls
95 lines (76 loc) · 3.13 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.cleanengine.coin.user.info.application;
import com.cleanengine.coin.user.domain.Account;
import com.cleanengine.coin.user.domain.Wallet;
import com.cleanengine.coin.user.info.infra.AccountRepository;
import com.cleanengine.coin.user.info.infra.WalletRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@DisplayName("지갑 서비스-Repository 통합테스트")
@ActiveProfiles({"dev", "h2-mem"})
@Transactional
@SpringBootTest
class WalletServiceTest {
@Autowired
private WalletService walletService;
@Autowired
private WalletRepository walletRepository;
@Autowired
private AccountRepository accountRepository;
private Account testAccount;
@BeforeEach
void setUp() {
// given
testAccount = Account.of(3, 0.0);
accountRepository.save(testAccount);
Wallet testWallet = Wallet.of("BTC", testAccount.getId(), 1000.0);
walletRepository.save(testWallet);
}
@DisplayName("계좌 ID로 조회 시 지갑이 정상 반환된다.")
@Test
void findByAccountId_thenReturnWallet() {
// when
List<Wallet> wallets = walletService.findByAccountId(testAccount.getId());
// then
assertThat(wallets).isNotEmpty();
assertThat(wallets.getFirst().getTicker()).isEqualTo("BTC");
}
@DisplayName("지갑이 성공적으로 저장된다.")
@Test
void save_thenCreateNewWallet() {
// when
Wallet newWallet = Wallet.of("TRUMP", testAccount.getId(), 5000.0);
Wallet savedWallet = walletService.save(newWallet);
// then
assertThat(savedWallet.getId()).isNotNull();
assertThat(savedWallet.getTicker()).isEqualTo("TRUMP");
assertThat(savedWallet.getSize()).isEqualTo(5000.0);
}
@DisplayName("유저 ID, 티커로 존재하는 지갑 조회 시 정상적으로 반환된다.")
@Test
void findWalletByUserIdAndTicker_ExistingWallet_thenReturnWallet() {
// when
Wallet wallet = walletService.findWalletByUserIdAndTicker(testAccount.getUserId(), "BTC");
// then
assertThat(wallet).isNotNull();
assertThat(wallet.getId()).isNotNull();
assertThat(wallet.getTicker()).isEqualTo("BTC");
assertThat(wallet.getSize()).isEqualTo(1000.0);
}
@DisplayName("유저 ID, 티커로 존재하지 않는 지갑 조회 시 빈 지갑이 새로 반환된다.")
@Test
void findWalletByUserIdAndTicker_NonExistingWallet_thenReturnEmptyWallet() {
// when
Wallet wallet = walletService.findWalletByUserIdAndTicker(testAccount.getUserId(), "TRUMP");
// then
assertThat(wallet).isNotNull();
assertThat(wallet.getTicker()).isEqualTo("TRUMP");
assertThat(wallet.getSize()).isEqualTo(0.0);
}
}