-
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 #231 from RandomJusicool/feature/230-my-write-boar…
…d-api-test-code 🔀 :: 자신이 작성한 게시물 가져오기 테스트 코드 작성
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/test/java/com/juicycool/backend/user/GetMyBoardServiceImplTest.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,71 @@ | ||
package com.juicycool.backend.user; | ||
|
||
import com.juicycool.backend.domain.board.Board; | ||
import com.juicycool.backend.domain.board.repository.BoardRepository; | ||
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.service.impl.GetMyBoardServiceImpl; | ||
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 GetMyBoardServiceImplTest { | ||
|
||
@Mock | ||
private UserUtil userUtil; | ||
|
||
@Mock | ||
private BoardRepository boardRepository; | ||
|
||
@Mock | ||
private UserConverter userConverter; | ||
|
||
@InjectMocks | ||
private GetMyBoardServiceImpl getMyBoardService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
@DisplayName("만약 자신이 쓴 게시물이 정상적으로 가져와진 경우") | ||
void If_post_you_write_imported_normally() { | ||
User user = new User(); | ||
|
||
when(userUtil.getCurrentUser()).thenReturn(user); | ||
|
||
Board board1 = new Board(); | ||
Board board2 = new Board(); | ||
|
||
List<Board> boardList = Arrays.asList(board1, board2); | ||
|
||
GetMyBoardResponseDto dto1 = GetMyBoardResponseDto.builder().build(); | ||
GetMyBoardResponseDto dto2 = GetMyBoardResponseDto.builder().build(); | ||
|
||
List<GetMyBoardResponseDto> dtoList = Arrays.asList(dto1, dto2); | ||
|
||
when(boardRepository.findByUser(user)).thenReturn(boardList); | ||
when(userConverter.toBoardDto(board1)).thenReturn(dto1); | ||
when(userConverter.toBoardDto(board2)).thenReturn(dto2); | ||
|
||
List<GetMyBoardResponseDto> result = getMyBoardService.execute(); | ||
|
||
assertEquals(dtoList, result); | ||
verify(userUtil, times(1)).getCurrentUser(); | ||
verify(boardRepository, times(1)).findByUser(user); | ||
verify(userConverter, times(1)).toBoardDto(board1); | ||
verify(userConverter, times(1)).toBoardDto(board2); | ||
} | ||
} |