Skip to content

Commit

Permalink
[tomato-market/plan#22] Controller Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunuk17 committed Nov 10, 2023
1 parent 781bdc9 commit 48f44b2
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class BoardControllerTest {

// Favorite
private FavoriteDto favoriteDto;
private List<FavoriteDto> favoriteDtoList;

@Autowired
private WebApplicationContext ctx;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 48f44b2

Please sign in to comment.