diff --git a/src/test/java/com/funeat/fixture/PageFixture.java b/src/test/java/com/funeat/fixture/PageFixture.java index 773658f4..b3fee538 100644 --- a/src/test/java/com/funeat/fixture/PageFixture.java +++ b/src/test/java/com/funeat/fixture/PageFixture.java @@ -6,6 +6,10 @@ import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + @SuppressWarnings("NonAsciiCharacters") public class PageFixture { @@ -34,12 +38,16 @@ public class PageFixture { return PageRequest.of(page, size); } - public static PageRequest 페이지요청_생성(final int page, final int size, final String sort) { - final String[] splitSort = sort.split(","); - final String order = splitSort[0]; - final Direction direction = Direction.fromString(splitSort[1]); + public static PageRequest 페이지요청_생성(final int page, final int size, final String... sorts) { + final List orders = new ArrayList<>(); + Arrays.stream(sorts).forEach(sort -> { + final String[] splitSort = sort.split(","); + final String property = splitSort[0]; + final Direction direction = Direction.fromString(splitSort[1]); + orders.add(new Sort.Order(direction, property)); + }); - return PageRequest.of(page, size, Sort.by(direction, order)); + return PageRequest.of(page, size, Sort.by(orders)); } public static PageDto 응답_페이지_생성(final Long totalDataCount, final Long totalPages, final boolean firstPage, diff --git a/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java b/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java index 22199a72..57159b22 100644 --- a/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java +++ b/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java @@ -7,6 +7,7 @@ import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; import static com.funeat.fixture.PageFixture.과거순; +import static com.funeat.fixture.PageFixture.아이디_내림차순; import static com.funeat.fixture.PageFixture.좋아요수_내림차순; import static com.funeat.fixture.PageFixture.최신순; import static com.funeat.fixture.PageFixture.페이지요청_생성; @@ -219,7 +220,7 @@ class findRecipeByMember_성공_테스트 { final var recipeImage1_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage1_2); - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when final var actual = recipeService.findRecipeByMember(member1.getId(), page); @@ -240,7 +241,7 @@ class findRecipeByMember_성공_테스트 { final var member1 = 멤버_멤버1_생성(); 단일_멤버_저장(member1); - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when final var actual = recipeService.findRecipeByMember(member1.getId(), page); @@ -260,7 +261,7 @@ class findRecipeByMember_실패_테스트 { void 존재하지_않는_멤버가_해당_멤버의_레시피를_조회하면_예외가_발생한다() { // given final var notExistMemberId = 99999L; - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when & then assertThatThrownBy(() -> recipeService.findRecipeByMember(notExistMemberId, page)) @@ -327,7 +328,7 @@ class 정렬_기준에_따른_테스트 { } @Test - void 꿀조합을_최신순으로_정렬할_수_있다() throws InterruptedException { + void 꿀조합을_최신순으로_정렬할_수_있다() { // given final var loginId = -1L; final var member1 = 멤버_멤버1_생성(); @@ -344,9 +345,7 @@ class 정렬_기준에_따른_테스트 { 복수_상품_저장(product1, product2, product3); final var recipe1_1 = 레시피_생성(member1, 1L); - Thread.sleep(100); final var recipe1_2 = 레시피_생성(member1, 3L); - Thread.sleep(100); final var recipe1_3 = 레시피_생성(member1, 2L); 복수_꿀조합_저장(recipe1_1, recipe1_2, recipe1_3); @@ -363,7 +362,7 @@ class 정렬_기준에_따른_테스트 { final var recipeImage1_2_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1_1, recipeImage1_2_1); - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when final var actual = recipeService.getSortingRecipes(loginId, page).getRecipes(); @@ -818,7 +817,7 @@ class findBookmarkRecipeByMember_성공_테스트 { final var request = 레시피북마크요청_생성(북마크O); recipeService.bookmarkRecipe(member1.getId(), recipe2.getId(), request); - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when final var actual = recipeService.findBookmarkRecipeByMember(member1.getId(), page); @@ -843,7 +842,7 @@ class findBookmarkRecipeByMember_성공_테스트 { final var member1 = 멤버_멤버1_생성(); 단일_멤버_저장(member1); - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when final var actual = recipeService.findBookmarkRecipeByMember(member1.getId(), page); @@ -863,7 +862,7 @@ class findBookmarkRecipeByMember_실패_테스트 { void 존재하지_않는_멤버가_해당_멤버의_저장한_레시피를_조회하면_예외가_발생한다() { // given final var notExistMemberId = 99999L; - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when & then assertThatThrownBy(() -> recipeService.findBookmarkRecipeByMember(notExistMemberId, page)) diff --git a/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java b/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java index 70aabf27..d08d0d90 100644 --- a/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java +++ b/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java @@ -5,6 +5,7 @@ import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; import static com.funeat.fixture.PageFixture.과거순; +import static com.funeat.fixture.PageFixture.아이디_내림차순; import static com.funeat.fixture.PageFixture.좋아요수_내림차순; import static com.funeat.fixture.PageFixture.최신순; import static com.funeat.fixture.PageFixture.페이지요청_생성; @@ -166,7 +167,7 @@ class findAllRecipes_성공_테스트 { } @Test - void 꿀조합을_최신순으로_정렬한다() throws InterruptedException { + void 꿀조합을_최신순으로_정렬한다() { // given final var member1 = 멤버_멤버1_생성(); final var member2 = 멤버_멤버2_생성(); @@ -182,9 +183,7 @@ class findAllRecipes_성공_테스트 { 복수_상품_저장(product1, product2, product3); final var recipe1_1 = 레시피_생성(member1, 1L); - Thread.sleep(100); final var recipe1_2 = 레시피_생성(member1, 3L); - Thread.sleep(100); final var recipe1_3 = 레시피_생성(member1, 2L); 복수_꿀조합_저장(recipe1_1, recipe1_2, recipe1_3); @@ -200,7 +199,7 @@ class findAllRecipes_성공_테스트 { final var recipeImage1_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage1_2); - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); final var expected = List.of(recipe1_3, recipe1_2, recipe1_1); // when @@ -371,7 +370,7 @@ class findBookmarkedRecipesByMember_성공_테스트 { 복수_레시피_북마크_저장(bookmarkRecipe1, bookmarkRecipe2, bookmarkRecipe3); final var expected = List.of(recipe3, recipe2); - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when final var actual = recipeRepository.findBookmarkedRecipesByMember(member, page).getContent(); @@ -392,7 +391,7 @@ class findBookmarkedRecipesByMember_성공_테스트 { 복수_꿀조합_저장(recipe1, recipe2); final var expected = Collections.emptyList(); - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when final var actual = recipeRepository.findBookmarkedRecipesByMember(member, page).getContent(); diff --git a/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/src/test/java/com/funeat/review/application/ReviewServiceTest.java index 6dbd7f38..4f1d4632 100644 --- a/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -6,6 +6,7 @@ import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; import static com.funeat.fixture.MemberFixture.멤버_비로그인_생성; +import static com.funeat.fixture.PageFixture.아이디_내림차순; import static com.funeat.fixture.PageFixture.최신순; import static com.funeat.fixture.PageFixture.페이지요청_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점2점_생성; @@ -674,7 +675,7 @@ class findReviewByMember_성공_테스트 { 복수_리뷰_저장(review1_1, review2_1, review2_2, review3_1, review3_2); // when - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); final var member1Id = member1.getId(); final var result = reviewService.findReviewByMember(member1Id, page); @@ -699,7 +700,7 @@ class findReviewByMember_실패_테스트 { void 존재하지_않은_사용자가_작성한_리뷰를_조회할때_예외가_발생한다() { // given final var notExistMemberId = 999999L; - final var page = 페이지요청_생성(0, 10, 최신순); + final var page = 페이지요청_생성(0, 10, 최신순, 아이디_내림차순); // when & then assertThatThrownBy(() -> reviewService.findReviewByMember(notExistMemberId, page))