@WebMvcTest(ReviewController.class) class ReviewControllerTest {
@Autowired private MockMvc mockMvc;
@MockBean private ReviewService reviewService;
@Test public void 리뷰를_생성한다() throws Exception { given(reviewService.addReview(eq(1L), any())).willReturn( Review.builder() .id(1004L) .name("JOKER") .score(3) .description("Mat-it-da") .build());
mockMvc.perform(post("/restaurants/1/reviews") .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"JOKER\", \"score\":3,\"description\" : \"Mat-it-da\"}")) .andExpect(status().isCreated()) .andExpect(header().string("location", "/restaurants/1/reviews/1004"));
verify(reviewService).addReview(eq(1L), any()); } }
|