Skip to content

Commit

Permalink
test: BoardController Like GET TEST 추가
Browse files Browse the repository at this point in the history
- 성공 케이스 & 실패 케이스
  • Loading branch information
LineYK committed Nov 30, 2023
1 parent 16f65bf commit 3f42fa0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/test/java/com/milk/milkweb/controller/BoardControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.milk.milkweb.service.BoardLikeService;
import com.milk.milkweb.service.BoardService;
import com.milk.milkweb.service.CustomOAuth2UserService;
import jakarta.persistence.EntityNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -271,4 +272,30 @@ void likeBoardBadRequestTest() throws Exception {
.content(objectMapper.writeValueAsString(boardLikeDto)))
.andExpect(status().isBadRequest());
}

@Test
@DisplayName("Board Like Get Success 테스트")
void getLikeTest() throws Exception {
// given
given(boardLikeService.getBoardLike(1L)).willReturn(100);

// when, then
mockMvc.perform(get("/board/like/{id}", 1L))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$").value(100));
}

@Test
@DisplayName("Board Like Get Fail 테스트")
void getLikeFailTest() throws Exception {
// given
doThrow(new EntityNotFoundException("Not Found")).when(boardLikeService).getBoardLike(1L);

// when, then
mockMvc.perform(get("/board/like/{id}", 1L))
.andExpect(status().isBadRequest())
.andExpect(content().contentType(MediaType.parseMediaType("text/plain;charset=UTF-8")))
.andExpect(jsonPath("$").value("Not Found"));
}
}

0 comments on commit 3f42fa0

Please sign in to comment.