From 48f44b238ad645c380dd5a78c6507d5a56625215 Mon Sep 17 00:00:00 2001 From: Hyunuk Date: Sat, 11 Nov 2023 03:26:06 +0900 Subject: [PATCH] [tomato-market/plan#22] Controller Test --- .../controller/BoardControllerTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/com/tomato/market/controller/BoardControllerTest.java b/src/test/java/com/tomato/market/controller/BoardControllerTest.java index f70cff2..bebb05c 100644 --- a/src/test/java/com/tomato/market/controller/BoardControllerTest.java +++ b/src/test/java/com/tomato/market/controller/BoardControllerTest.java @@ -94,6 +94,7 @@ public class BoardControllerTest { // Favorite private FavoriteDto favoriteDto; + private List favoriteDtoList; @Autowired private WebApplicationContext ctx; @@ -148,6 +149,9 @@ void setUp() { // Favorite favoriteDto = FavoriteDto.builder().userId(userId).postNum(postNum).status(1).build(); + favoriteDtoList = new ArrayList<>(); + favoriteDtoList.add(favoriteDto); + favoriteDtoList.add(favoriteDto); } @Test @@ -479,4 +483,30 @@ void getFavoriteFailure() throws Exception { verify(boardService).getFavorite(userId, postNum); } + + @Test + @DisplayName("게시글_관심_목록_조회_성공") + void getFavoriteListSuccess() throws Exception { + given(boardService.getFavoriteList(userId)).willReturn(favoriteDtoList); + + mockMvc.perform(get("/api/board/favorite/list").param("userId", userId)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.message", is("관심 목록 조회 성공"))) + .andDo(print()); + + verify(boardService).getFavoriteList(userId); + } + + @Test + @DisplayName("게시글_관심_목록_조회_실패") + void getFavoriteListFailure() throws Exception { + given(boardService.getFavoriteList(userId)).willThrow(new BoardException("관심 목록 조회에 실패했습니다.")); + + mockMvc.perform(get("/api/board/favorite/list").param("userId", userId)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.message", is("관심 목록 조회에 실패했습니다."))) + .andDo(print()); + + verify(boardService).getFavoriteList(userId); + } }