-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from RandomJusicool/feature/232-my-have-ing-s…
…tock-list-test-code 🔀 :: 보유 중인 주식 테스트 코드 작성
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/test/java/com/juicycool/backend/user/GetMyOwnedStockServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.juicycool.backend.user; | ||
|
||
import com.juicycool.backend.domain.stock.OwnedStocks; | ||
import com.juicycool.backend.domain.stock.repository.OwnedStocksRepository; | ||
import com.juicycool.backend.domain.user.User; | ||
import com.juicycool.backend.domain.user.converter.UserConverter; | ||
import com.juicycool.backend.domain.user.presentation.dto.response.GetMyBoardResponseDto; | ||
import com.juicycool.backend.domain.user.presentation.dto.response.GetMyOwnedStockResponseDto; | ||
import com.juicycool.backend.domain.user.service.impl.GetMyOwnedStockServiceImpl; | ||
import com.juicycool.backend.domain.user.util.UserUtil; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class GetMyOwnedStockServiceImplTest { | ||
|
||
@Mock | ||
private OwnedStocksRepository ownedStocksRepository; | ||
|
||
@Mock | ||
private UserUtil userUtil; | ||
|
||
@Mock | ||
private UserConverter userConverter; | ||
|
||
@InjectMocks | ||
private GetMyOwnedStockServiceImpl getMyOwnedStockService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
@DisplayName("만약 내가 가지고 있는 주식 리스트가 불러와진 경우") | ||
void If_list_of_share_have_is_imported() { | ||
User user = new User(); | ||
|
||
when(userUtil.getCurrentUser()).thenReturn(user); | ||
|
||
OwnedStocks ownedStocks1 = new OwnedStocks(); | ||
OwnedStocks ownedStocks2 = new OwnedStocks(); | ||
|
||
List<OwnedStocks> ownedStocksList = Arrays.asList(ownedStocks1, ownedStocks2); | ||
|
||
GetMyOwnedStockResponseDto dto1 = GetMyOwnedStockResponseDto.builder().build(); | ||
GetMyOwnedStockResponseDto dto2 = GetMyOwnedStockResponseDto.builder().build(); | ||
|
||
List<GetMyOwnedStockResponseDto> dtoList = Arrays.asList(dto1, dto2); | ||
|
||
when(ownedStocksRepository.findByUser(user)).thenReturn(ownedStocksList); | ||
when(userConverter.toDto(ownedStocks1)).thenReturn(dto1); | ||
when(userConverter.toDto(ownedStocks2)).thenReturn(dto2); | ||
|
||
List<GetMyOwnedStockResponseDto> result = getMyOwnedStockService.execute(); | ||
|
||
assertEquals(result, dtoList); | ||
when(ownedStocksRepository.findByUser(user)).thenReturn(ownedStocksList); | ||
verify(userUtil, times(1)).getCurrentUser(); | ||
verify(ownedStocksRepository, times(1)).findByUser(user); | ||
verify(userConverter, times(1)).toDto(ownedStocks1); | ||
verify(userConverter, times(1)).toDto(ownedStocks2); | ||
} | ||
} |