Skip to content

Commit 8c1a228

Browse files
committed
test: 지도 범위 내 마커형 다이어리 조회 API 단위 테스트 작성
1 parent 8b1f577 commit 8c1a228

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/test/java/com/example/log4u/domain/Map/service/MapServiceTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.assertj.core.api.AssertionsForInterfaceTypes.*;
44
import static org.mockito.BDDMockito.*;
55

6+
import java.time.LocalDateTime;
67
import java.util.List;
78

89
import org.junit.jupiter.api.DisplayName;
@@ -12,13 +13,16 @@
1213
import org.mockito.Mock;
1314
import org.mockito.junit.jupiter.MockitoExtension;
1415

16+
import com.example.log4u.domain.diary.repository.DiaryRepository;
17+
import com.example.log4u.domain.map.dto.response.DiaryMarkerResponseDto;
1518
import com.example.log4u.fixture.AreaClusterFixture;
1619
import com.example.log4u.domain.map.dto.response.DiaryClusterResponseDto;
1720
import com.example.log4u.domain.map.repository.SidoAreasDiaryCountRepository;
1821
import com.example.log4u.domain.map.repository.SidoAreasRepository;
1922
import com.example.log4u.domain.map.repository.SiggAreasDiaryCountRepository;
2023
import com.example.log4u.domain.map.repository.SiggAreasRepository;
2124
import com.example.log4u.domain.map.service.MapService;
25+
import com.example.log4u.fixture.DiaryMarkerFixture;
2226

2327
@DisplayName("지도 API 단위 테스트")
2428
@ExtendWith(MockitoExtension.class)
@@ -29,12 +33,12 @@ class MapServiceTest {
2933

3034
@Mock
3135
private SidoAreasRepository sidoAreasRepository;
32-
@Mock
33-
private SidoAreasDiaryCountRepository sidoAreasDiaryCountRepository;
36+
3437
@Mock
3538
private SiggAreasRepository siggAreasRepository;
39+
3640
@Mock
37-
private SiggAreasDiaryCountRepository siggAreasDiaryCountRepository;
41+
private DiaryRepository diaryRepository;
3842

3943
@DisplayName("성공 테스트: 줌레벨이 10 이하이면 시/도 클러스터 조회")
4044
@Test
@@ -75,4 +79,25 @@ void getDiaryClusters_siggAreas_success() {
7579
assertThat(result.get(1).diaryCount()).isEqualTo(30L);
7680
verify(siggAreasRepository).findSiggAreaClusters(south, north, west, east);
7781
}
82+
83+
@DisplayName("성공 테스트: 마커 조회 (줌 14 이상)")
84+
@Test
85+
void getDiariesInBounds_success() {
86+
// given
87+
double south = 37.0, north = 38.0, west = 126.0, east = 127.0;
88+
List<DiaryMarkerResponseDto> markers = DiaryMarkerFixture.createDiaryMarkers();
89+
90+
given(diaryRepository.findDiariesInBounds(south, north, west, east))
91+
.willReturn(markers);
92+
93+
// when
94+
List<DiaryMarkerResponseDto> result = mapService.getDiariesInBounds(south, north, west, east);
95+
96+
// then
97+
assertThat(result).hasSize(2);
98+
assertThat(result.get(0).title()).isEqualTo("첫번째 다이어리");
99+
assertThat(result.get(1).likeCount()).isEqualTo(7L);
100+
verify(diaryRepository).findDiariesInBounds(south, north, west, east);
101+
}
102+
78103
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.log4u.fixture;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.List;
5+
6+
import com.example.log4u.domain.map.dto.response.DiaryMarkerResponseDto;
7+
8+
public class DiaryMarkerFixture {
9+
10+
public static DiaryMarkerResponseDto createDiaryMarker(Long id, String title, String thumbnailUrl, Long likeCount, Double lat, Double lon, LocalDateTime createdAt) {
11+
return new DiaryMarkerResponseDto(id, title, thumbnailUrl, likeCount, lat, lon, createdAt);
12+
}
13+
14+
public static List<DiaryMarkerResponseDto> createDiaryMarkers() {
15+
return List.of(
16+
createDiaryMarker(1L, "첫번째 다이어리", "https://example.com/thumb1.jpg", 12L, 37.5665, 126.9780, LocalDateTime.now().minusDays(1)),
17+
createDiaryMarker(2L, "두번째 다이어리", "https://example.com/thumb2.jpg", 7L, 37.5678, 126.9900, LocalDateTime.now().minusDays(2))
18+
);
19+
}
20+
}

0 commit comments

Comments
 (0)