From 726459fe7b851a3c317d4d6ace565e170e4c14de Mon Sep 17 00:00:00 2001 From: Wonjeong Kim Date: Sun, 24 Mar 2024 22:38:23 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20BoardServiceTest.java=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/service/board/BoardServiceTest.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/test/java/server/inuappcenter/kr/service/board/BoardServiceTest.java b/src/test/java/server/inuappcenter/kr/service/board/BoardServiceTest.java index dacac6d..502f9bf 100644 --- a/src/test/java/server/inuappcenter/kr/service/board/BoardServiceTest.java +++ b/src/test/java/server/inuappcenter/kr/service/board/BoardServiceTest.java @@ -11,6 +11,9 @@ import server.inuappcenter.kr.data.domain.board.Board; import server.inuappcenter.kr.data.domain.board.FaqBoard; import server.inuappcenter.kr.data.dto.request.FaqBoardRequestDto; +import server.inuappcenter.kr.data.dto.response.BoardResponseDto; +import server.inuappcenter.kr.data.dto.response.FaqBoardResponseDto; +import server.inuappcenter.kr.data.redis.repository.BoardResponseRedisRepository; import server.inuappcenter.kr.data.repository.BoardRepository; import server.inuappcenter.kr.exception.customExceptions.CustomNotFoundException; import server.inuappcenter.kr.service.boardService.BoardService; @@ -25,31 +28,28 @@ public class BoardServiceTest { @Mock private BoardRepository boardRepository; + @Mock + private BoardResponseRedisRepository boardResponseRedisRepository; @InjectMocks private BoardService boardService; -// @DisplayName("게시판 가져오기 테스트") -// @Test -// public void getBoard() { -// // given -// Long givenId = 1L; -// Board exceptedEntity = new FaqBoard(new FaqBoardRequestDto( -// "서버", "질문입니다.", "답변입니다." -// )); -// given(boardRepository.findById(givenId)).willReturn(Optional.of(exceptedEntity)); -// // when -// Board result = boardService.findBoard(givenId); -// // then -// assertEquals(exceptedEntity.getId(), result.getId()); -// assertEquals(exceptedEntity.getBody(), result.getBody()); -// -// // case2 (게시판이 존재하지 않을 경우) -// // given -// given(boardRepository.findById(givenId)).willReturn(Optional.empty()); -// // when, then -// assertThrows(CustomNotFoundException.class, () -> boardService.getBoard(givenId)); -// } + @DisplayName("게시판 가져오기 테스트") + @Test + public void getBoard() { + // given + Long givenId = 1L; + Board exceptedEntity = new FaqBoard(new FaqBoardRequestDto( + "서버", "질문입니다.", "답변입니다." + )); + BoardResponseDto responseDto = FaqBoardResponseDto.entityToDto(exceptedEntity); + given(boardResponseRedisRepository.findById(givenId)).willReturn(Optional.of(responseDto)); + // when + BoardResponseDto result = boardService.findBoard(givenId); + // then + assertEquals(exceptedEntity.getId(), result.getId()); + assertEquals(exceptedEntity.getBody(), result.getBody()); + } @DisplayName("게시판 저장 테스트") @Test