Skip to content

Commit

Permalink
[tomato-market/plan#22] Service Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunuk17 committed Nov 10, 2023
1 parent 48f44b2 commit 4f41109
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/test/java/com/tomato/market/service/BoardServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public class BoardServiceTest {

// Favorite
private FavoriteDto favoriteDto;
private List<FavoriteDto> favoriteDtoList;
private FavoriteEntity favoriteEntity;
private List<FavoriteEntity> favoriteEntities;


@BeforeEach
Expand Down Expand Up @@ -114,8 +116,14 @@ void setUp() {
.postNum(postNum)
.status(1)
.build();
favoriteDtoList = new ArrayList<>();
favoriteDtoList.add(favoriteDto);
favoriteDtoList.add(favoriteDto);

favoriteEntity = FavoriteDto.toFavoriteEntity(favoriteDto);
favoriteEntities = new ArrayList<>();
favoriteEntities.add(favoriteEntity);
favoriteEntities.add(favoriteEntity);
}

@Test
Expand Down Expand Up @@ -387,4 +395,29 @@ void getFavoriteSuccess() {

verify(boardDao).findByUserIdAndPostNum(any(String.class), any(Integer.class));
}

@Test
@DisplayName("게시글_관심_목록_조회_성공")
void getFavoriteListSuccess() {
given(boardDao.findByUserId(userId)).willReturn(favoriteEntities);

BoardServiceImpl boardService = new BoardServiceImpl(boardDao);
Assertions.assertEquals(boardService.getFavoriteList(userId).toString(), favoriteDtoList.toString());

verify(boardDao).findByUserId(userId);
}

@Test
@DisplayName("게시글_관심_목록_조회_실패")
void getFavoriteListFailure() {
given(boardDao.findByUserId(userId)).willReturn(null);

BoardServiceImpl boardService = new BoardServiceImpl(boardDao);
BoardException exception = Assertions.assertThrows(BoardException.class, () -> {
boardService.getFavoriteList(userId);
});
Assertions.assertEquals(exception.getMessage(), "관심 목록 조회에 실패했습니다.");

verify(boardDao).findByUserId(userId);
}
}

0 comments on commit 4f41109

Please sign in to comment.