Service 메서드

@Transactional
public void deletePost(Long postId) {
Post foundPost = postRepository.findById(postId)
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 게시물 번호입니다."));

postRepository.delete(foundPost);
}


Controller 메서드

@Test
void deletePostApi_Nonexistence() throws Exception {
// given
when(postService.deletePost(1L))
.thenThrow(new IllegalArgumentException("존재하지 않는 게시물 번호입니다."));

// when
ResultActions result = mvc.perform(delete("/api/v1/posts/1"));

// then
result.andExpect(status().isBadRequest())
.andDo(print());
}


when ~ thenThow에서 when에서 계속 빨간줄 뜨는데 검색해도 감이 안잡히네