Skip to content

Commit 941bcaa

Browse files
committed
test : 테스트코드 반영
1 parent 1b34bd6 commit 941bcaa

File tree

4 files changed

+119
-3
lines changed

4 files changed

+119
-3
lines changed

orury-client/src/test/java/org/orury/client/config/FacadeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void setUp() {
5959
meetingService = mock(MeetingService.class);
6060
notificationService = mock(NotificationService.class);
6161

62-
userFacade = new UserFacade(userService, postService, reviewService, commentService, meetingService, crewService);
62+
userFacade = new UserFacade(userService, postService, reviewService, commentService, meetingService, crewService, gymService);
6363
gymFacade = new GymFacade(gymService, reviewService);
6464
commentFacade = new CommentFacade(commentService, postService, userService, notificationService);
6565
crewFacade = new CrewFacade(crewService, userService);

orury-client/src/test/java/org/orury/client/gym/application/GymServiceImplTest.java

+30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.orury.domain.gym.domain.dto.GymLikeDto;
1111
import org.orury.domain.gym.domain.entity.Gym;
1212
import org.orury.domain.gym.domain.entity.GymLikePK;
13+
import org.springframework.data.domain.PageRequest;
1314

1415
import java.time.DayOfWeek;
1516
import java.time.LocalTime;
@@ -125,6 +126,35 @@ void when_NothingSearched_Then_RetrieveEmptyList() {
125126
.findGymsBySearchWord(anyString());
126127
}
127128

129+
@Test
130+
@DisplayName("유저id와 cursor에 대해, 해당 유저가 좋아요한 GymDto 목록을 반환한다.")
131+
void should_RetrieveGymDtoListByUserLiked() {
132+
// given
133+
Long userId = 98L;
134+
Long cursor = 20L;
135+
List<Gym> gyms = List.of(
136+
createGym().id(19L).build().get(),
137+
createGym().id(14L).build().get(),
138+
createGym().id(3L).build().get()
139+
);
140+
List<GymDto> expectedGymDtos = List.of(
141+
GymDto.from(gyms.get(0)),
142+
GymDto.from(gyms.get(1)),
143+
GymDto.from(gyms.get(2))
144+
);
145+
146+
given(gymReader.findGymsByUserLiked(userId, cursor, PageRequest.of(0, 15)))
147+
.willReturn(gyms);
148+
149+
// when
150+
List<GymDto> actualGymDtos = gymService.getGymDtosByUserLiked(userId, cursor);
151+
152+
// then
153+
assertEquals(expectedGymDtos, actualGymDtos);
154+
then(gymReader).should(times(1))
155+
.findGymsByUserLiked(anyLong(), anyLong(), any());
156+
}
157+
128158
@Test
129159
@DisplayName("암장에 대한 유저의 암장 좋아요 기존에 없다면, 정상적으로 암장 좋아요를 생성한다.")
130160
void should_CreateGymLike() {

orury-client/src/test/java/org/orury/client/user/application/UserFacadeTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import org.orury.client.global.WithCursorResponse;
77
import org.orury.client.user.interfaces.request.UserInfoRequest;
88
import org.orury.client.user.interfaces.response.MyCommentResponse;
9+
import org.orury.client.user.interfaces.response.MyGymResponse;
910
import org.orury.client.user.interfaces.response.MyPostResponse;
1011
import org.orury.client.user.interfaces.response.MyReviewResponse;
1112
import org.orury.domain.comment.domain.dto.CommentDto;
13+
import org.orury.domain.gym.domain.dto.GymDto;
1214
import org.orury.domain.post.domain.dto.PostDto;
1315
import org.orury.domain.review.domain.dto.ReviewDto;
1416
import org.orury.domain.user.domain.dto.UserDto;
@@ -27,6 +29,7 @@
2729
import static org.orury.client.ClientFixtureFactory.TestReportRequest.createReportRequest;
2830
import static org.orury.client.ClientFixtureFactory.TestUserInfoRequest.createUserInfoRequest;
2931
import static org.orury.domain.CommentDomainFixture.TestCommentDto.createCommentDto;
32+
import static org.orury.domain.GymDomainFixture.TestGymDto.createGymDto;
3033
import static org.orury.domain.PostDomainFixture.TestPostDto.createPostDto;
3134
import static org.orury.domain.ReviewDomainFixture.TestReviewDto.createReviewDto;
3235
import static org.orury.domain.UserDomainFixture.TestUserDto.createUserDto;
@@ -166,6 +169,32 @@ void should_returnWithCommentsCursorResponse() {
166169
then(commentService).should(times(1)).getCommentDtosByUserId(anyLong(), anyLong());
167170
}
168171

172+
@Test
173+
@DisplayName("getGymsByUserLiked(Long id, Long cursor) test: id, cursor 값을 입력받아 내가 저장한 암장목록을 반환한다. [성공] ")
174+
void should_returnWithGymsCursorResponse() {
175+
//given
176+
Long userId = 1L;
177+
Long cursor = 0L;
178+
179+
List<GymDto> gymDtos = new ArrayList<>();
180+
for (int i = 10; i >= 1; i--) {
181+
gymDtos.add(createGymDto((long) i).build().get());
182+
}
183+
184+
WithCursorResponse<MyGymResponse> response = WithCursorResponse.of(gymDtos.stream()
185+
.map(MyGymResponse::of)
186+
.toList(), cursor);
187+
188+
given(gymService.getGymDtosByUserLiked(anyLong(), anyLong())).willReturn(gymDtos);
189+
190+
//when
191+
WithCursorResponse<MyGymResponse> actualResponse = userFacade.getGymsByUserLiked(userId, cursor);
192+
193+
//then
194+
assertThat(actualResponse).isEqualTo(response);
195+
then(gymService).should(times(1)).getGymDtosByUserLiked(anyLong(), anyLong());
196+
}
197+
169198
@Test
170199
@DisplayName("deleteUser(Long id) test: userId를 받아 해당하는 User를 삭제한다. [성공] ")
171200
void should_deleteUser() {

orury-domain/src/test/java/org/orury/domain/gym/infrastructure/GymReaderImplTest.java

+59-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import org.junit.jupiter.api.DisplayName;
44
import org.junit.jupiter.api.Test;
55
import org.orury.domain.config.InfrastructureTest;
6+
import org.orury.domain.global.constants.NumberConstants;
67
import org.orury.domain.gym.domain.entity.Gym;
78
import org.orury.domain.gym.domain.entity.GymLikePK;
9+
import org.springframework.data.domain.PageRequest;
10+
import org.springframework.data.domain.Pageable;
811

912
import java.util.Collections;
1013
import java.util.List;
@@ -13,12 +16,12 @@
1316

1417
import static org.junit.jupiter.api.Assertions.assertFalse;
1518
import static org.junit.jupiter.api.Assertions.assertTrue;
16-
import static org.mockito.ArgumentMatchers.anyLong;
17-
import static org.mockito.ArgumentMatchers.anyString;
19+
import static org.mockito.ArgumentMatchers.*;
1820
import static org.mockito.BDDMockito.given;
1921
import static org.mockito.BDDMockito.then;
2022
import static org.mockito.Mockito.times;
2123
import static org.orury.domain.GymDomainFixture.TestGym.createGym;
24+
import static org.orury.domain.GymDomainFixture.TestGymLike.createGymLike;
2225
import static org.orury.domain.GymDomainFixture.TestGymLikePK.createGymLikePK;
2326

2427
@DisplayName("[Reader] 암장 ReaderImpl 테스트")
@@ -140,6 +143,60 @@ void when_GymsInAreaGrid_Then_ReturnGymList() {
140143
.findByLatitudeBetweenAndLongitudeBetweenOrderByLikeCount(bottom, top, left, right);
141144
}
142145

146+
@Test
147+
@DisplayName("유저id로 좋아요한 암장 리스트를 반환한다. (첫 조회인 경우)")
148+
void when_FirstGymsLikedByUser_Then_ReturnGymList() {
149+
// given
150+
Long userId = 1L;
151+
Long cursor = NumberConstants.FIRST_CURSOR;
152+
Pageable pageRequest = PageRequest.of(0, NumberConstants.GYM_PAGINATION_SIZE);
153+
154+
given(gymLikeRepository.findByGymLikePK_UserIdOrderByGymLikePKDesc(userId, pageRequest))
155+
.willReturn(List.of(
156+
createGymLike(11L, userId).build().get(),
157+
createGymLike(10L, userId).build().get()
158+
));
159+
160+
given(gymRepository.findById(anyLong()))
161+
.willReturn(Optional.of(createGym(1L).build().get()));
162+
163+
// when
164+
gymReader.findGymsByUserLiked(userId, cursor, pageRequest);
165+
166+
// then
167+
then(gymLikeRepository).should(times(1))
168+
.findByGymLikePK_UserIdOrderByGymLikePKDesc(anyLong(), any(Pageable.class));
169+
then(gymLikeRepository).should(times(0))
170+
.findByGymLikePK_UserIdAndGymLikePK_GymIdLessThanOrderByGymLikePKDesc(anyLong(), anyLong(), any(Pageable.class));
171+
}
172+
173+
@Test
174+
@DisplayName("유저id로 좋아요한 암장 리스트를 반환한다. (첫 조회가 아닌 경우)")
175+
void when_GymsLikedByUser_Then_ReturnGymList() {
176+
// given
177+
Long userId = 1L;
178+
Long cursor = 2L;
179+
Pageable pageRequest = PageRequest.of(0, NumberConstants.GYM_PAGINATION_SIZE);
180+
181+
given(gymLikeRepository.findByGymLikePK_UserIdAndGymLikePK_GymIdLessThanOrderByGymLikePKDesc(userId, cursor, pageRequest))
182+
.willReturn(List.of(
183+
createGymLike(11L, userId).build().get(),
184+
createGymLike(10L, userId).build().get()
185+
));
186+
187+
given(gymRepository.findById(anyLong()))
188+
.willReturn(Optional.of(createGym(1L).build().get()));
189+
190+
// when
191+
gymReader.findGymsByUserLiked(userId, cursor, pageRequest);
192+
193+
// then
194+
then(gymLikeRepository).should(times(0))
195+
.findByGymLikePK_UserIdOrderByGymLikePKDesc(anyLong(), any(Pageable.class));
196+
then(gymLikeRepository).should(times(1))
197+
.findByGymLikePK_UserIdAndGymLikePK_GymIdLessThanOrderByGymLikePKDesc(anyLong(), anyLong(), any(Pageable.class));
198+
}
199+
143200
@Test
144201
@DisplayName("존재하는 (userId와 gymId로 구성된) 암장좋아요PK가 들어오면, true를 반환한다.")
145202
void when_ExistingGymLikePK_Then_ReturnTrue() {

0 commit comments

Comments
 (0)