|
| 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 | +} |
0 commit comments