Skip to content

Commit 8ea6f54

Browse files
committed
test: 지도 클러스터 API 단위 테스트 추가
1 parent d150cf3 commit 8ea6f54

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.example.log4u.domain.Map.service;
2+
3+
import static org.assertj.core.api.AssertionsForInterfaceTypes.*;
4+
import static org.mockito.BDDMockito.*;
5+
6+
import java.util.List;
7+
8+
import org.junit.jupiter.api.DisplayName;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.extension.ExtendWith;
11+
import org.mockito.InjectMocks;
12+
import org.mockito.Mock;
13+
import org.mockito.junit.jupiter.MockitoExtension;
14+
15+
import com.example.log4u.fixture.AreaClusterFixture;
16+
import com.example.log4u.domain.map.dto.response.DiaryClusterResponseDto;
17+
import com.example.log4u.domain.map.repository.SidoAreasDiaryCountRepository;
18+
import com.example.log4u.domain.map.repository.SidoAreasRepository;
19+
import com.example.log4u.domain.map.repository.SiggAreasDiaryCountRepository;
20+
import com.example.log4u.domain.map.repository.SiggAreasRepository;
21+
import com.example.log4u.domain.map.service.MapService;
22+
23+
@DisplayName("지도 API 단위 테스트")
24+
@ExtendWith(MockitoExtension.class)
25+
class MapServiceTest {
26+
27+
@InjectMocks
28+
private MapService mapService;
29+
30+
@Mock
31+
private SidoAreasRepository sidoAreasRepository;
32+
@Mock
33+
private SidoAreasDiaryCountRepository sidoAreasDiaryCountRepository;
34+
@Mock
35+
private SiggAreasRepository siggAreasRepository;
36+
@Mock
37+
private SiggAreasDiaryCountRepository siggAreasDiaryCountRepository;
38+
39+
@DisplayName("성공 테스트: 줌레벨이 10 이하이면 시/도 클러스터 조회")
40+
@Test
41+
void getDiaryClusters_sidoAreas_success() {
42+
// given
43+
double south = 37.0, north = 38.0, west = 126.0, east = 127.0;
44+
int zoom = 9;
45+
46+
given(sidoAreasRepository.findSidoAreaClusters(south, north, west, east))
47+
.willReturn(AreaClusterFixture.sidoAreaList());
48+
49+
// when
50+
List<DiaryClusterResponseDto> result = mapService.getDiaryClusters(south, north, west, east, zoom);
51+
52+
// then
53+
assertThat(result).hasSize(2);
54+
assertThat(result.getFirst().areaName()).isEqualTo("서울특별시");
55+
assertThat(result.getFirst().diaryCount()).isEqualTo(100L);
56+
verify(sidoAreasRepository).findSidoAreaClusters(south, north, west, east);
57+
}
58+
59+
@DisplayName("성공 테스트: 줌레벨이 11 이상이면 시군구 클러스터 조회")
60+
@Test
61+
void getDiaryClusters_siggAreas_success() {
62+
// given
63+
double south = 37.0, north = 38.0, west = 126.0, east = 127.0;
64+
int zoom = 12;
65+
66+
given(siggAreasRepository.findSiggAreaClusters(south, north, west, east))
67+
.willReturn(AreaClusterFixture.siggAreaList());
68+
69+
// when
70+
List<DiaryClusterResponseDto> result = mapService.getDiaryClusters(south, north, west, east, zoom);
71+
72+
// then
73+
assertThat(result).hasSize(2);
74+
assertThat(result.get(1).areaName()).isEqualTo("송파구");
75+
assertThat(result.get(1).diaryCount()).isEqualTo(30L);
76+
verify(siggAreasRepository).findSiggAreaClusters(south, north, west, east);
77+
}
78+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.example.log4u.fixture;
2+
3+
4+
import java.util.List;
5+
6+
import com.example.log4u.domain.map.dto.response.AreaClusterProjection;
7+
8+
public class AreaClusterFixture {
9+
10+
public static AreaClusterProjection createSidoArea(Long id, String name, double lat, double lon, long diaryCount) {
11+
return new AreaClusterProjectionStub(id, name, lat, lon, diaryCount);
12+
}
13+
14+
public static AreaClusterProjection createSiggArea(Long id, String name, double lat, double lon, long diaryCount) {
15+
return new AreaClusterProjectionStub(id, name, lat, lon, diaryCount);
16+
}
17+
18+
public static List<AreaClusterProjection> sidoAreaList() {
19+
return List.of(
20+
createSidoArea(1L, "서울특별시", 37.5, 126.9, 100L),
21+
createSidoArea(2L, "경기도", 37.6, 127.0, 80L)
22+
);
23+
}
24+
25+
public static List<AreaClusterProjection> siggAreaList() {
26+
return List.of(
27+
createSiggArea(11L, "강남구", 37.4, 127.0, 42L),
28+
createSiggArea(12L, "송파구", 37.5, 127.1, 30L)
29+
);
30+
}
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.log4u.fixture;
2+
3+
import com.example.log4u.domain.map.dto.response.AreaClusterProjection;
4+
5+
public class AreaClusterProjectionStub implements AreaClusterProjection {
6+
private final Long id;
7+
private final String name;
8+
private final Double lat;
9+
private final Double lon;
10+
private final Long diaryCount;
11+
12+
public AreaClusterProjectionStub(Long id, String name, Double lat, Double lon, Long diaryCount) {
13+
this.id = id;
14+
this.name = name;
15+
this.lat = lat;
16+
this.lon = lon;
17+
this.diaryCount = diaryCount;
18+
}
19+
20+
@Override public Long getId() { return id; }
21+
@Override public String getName() { return name; }
22+
@Override public Double getLat() { return lat; }
23+
@Override public Double getLon() { return lon; }
24+
@Override public Long getDiaryCount() { return diaryCount; }
25+
}
26+

0 commit comments

Comments
 (0)