Skip to content

Commit 3df1c6e

Browse files
committed
Test: UserControllerTest 개선
1 parent 0379dfb commit 3df1c6e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/test/java/com/back/domain/user/controller/UserControllerTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.List;
3131

3232
import static org.assertj.core.api.Assertions.assertThat;
33+
import static org.hamcrest.Matchers.containsInAnyOrder;
3334
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
3435
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
3536
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
@@ -702,8 +703,9 @@ void getMyPosts_success() throws Exception {
702703
.andExpect(jsonPath("$.message").value("내 게시글 목록이 조회되었습니다."))
703704
.andExpect(jsonPath("$.data.items").isArray())
704705
.andExpect(jsonPath("$.data.items.length()").value(2))
705-
.andExpect(jsonPath("$.data.items[0].title").value("두 번째 글")) // 최신순(createdAt desc)
706-
.andExpect(jsonPath("$.data.items[1].title").value("첫 번째 글"));
706+
.andExpect(jsonPath("$.data.items[*].title").value(
707+
containsInAnyOrder("첫 번째 글", "두 번째 글")
708+
));
707709
}
708710

709711
@Test
@@ -841,8 +843,9 @@ void getMyComments_success() throws Exception {
841843
.andExpect(jsonPath("$.message").value("내 댓글 목록이 조회되었습니다."))
842844
.andExpect(jsonPath("$.data.items").isArray())
843845
.andExpect(jsonPath("$.data.items.length()").value(3))
844-
.andExpect(jsonPath("$.data.items[0].content").value("감사합니다! 더 공부해볼게요."))
845-
.andExpect(jsonPath("$.data.items[1].content").value("정말 도움이 많이 됐어요!"));
846+
.andExpect(jsonPath("$.data.items[*].content").value(
847+
containsInAnyOrder("코딩 박사의 스프링 교재도 추천합니다.", "정말 도움이 많이 됐어요!", "감사합니다! 더 공부해볼게요.")
848+
));
846849
}
847850

848851
@Test
@@ -980,8 +983,9 @@ void getMyBookmarks_success() throws Exception {
980983
.andExpect(jsonPath("$.code").value("SUCCESS_200"))
981984
.andExpect(jsonPath("$.message").value("내 북마크 게시글 목록이 조회되었습니다."))
982985
.andExpect(jsonPath("$.data.items.length()").value(2))
983-
.andExpect(jsonPath("$.data.items[0].title").value("테스트 코드 작성 가이드"))
984-
.andExpect(jsonPath("$.data.items[1].title").value("JPA 영속성 전이 완벽 정리"));
986+
.andExpect(jsonPath("$.data.items[*].title").value(
987+
containsInAnyOrder("JPA 영속성 전이 완벽 정리", "테스트 코드 작성 가이드")
988+
));
985989
}
986990

987991
@Test

0 commit comments

Comments
 (0)