diff --git a/server/src/main/java/com/talkka/server/bus/dto/BusRouteStationCreateDto.java b/server/src/main/java/com/talkka/server/bus/dto/BusRouteStationCreateDto.java index a3004543..4186960c 100644 --- a/server/src/main/java/com/talkka/server/bus/dto/BusRouteStationCreateDto.java +++ b/server/src/main/java/com/talkka/server/bus/dto/BusRouteStationCreateDto.java @@ -1,7 +1,5 @@ package com.talkka.server.bus.dto; -import com.talkka.server.bus.dao.BusStationEntity; - import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -20,7 +18,6 @@ public class BusRouteStationCreateDto { private String apiRouteId; private String apiStationId; - private BusStationEntity station; private Short stationSeq; private String stationName; } diff --git a/server/src/test/java/com/talkka/server/bus/service/BusFactory.java b/server/src/test/java/com/talkka/server/bus/service/BusFactory.java new file mode 100644 index 00000000..29d0f5c8 --- /dev/null +++ b/server/src/test/java/com/talkka/server/bus/service/BusFactory.java @@ -0,0 +1,169 @@ +package com.talkka.server.bus.service; + +import java.math.BigDecimal; + +import com.talkka.server.bus.dao.BusRouteEntity; +import com.talkka.server.bus.dao.BusRouteStationEntity; +import com.talkka.server.bus.dao.BusStationEntity; +import com.talkka.server.bus.dto.BusRouteCreateDto; +import com.talkka.server.bus.dto.BusRouteRespDto; +import com.talkka.server.bus.dto.BusRouteStationCreateDto; +import com.talkka.server.bus.dto.BusRouteStationRespDto; +import com.talkka.server.bus.dto.BusStationCreateDto; +import com.talkka.server.bus.dto.BusStationRespDto; +import com.talkka.server.bus.enums.BusRouteType; +import com.talkka.server.bus.enums.CenterStation; +import com.talkka.server.bus.enums.DistrictCode; +import com.talkka.server.bus.enums.TurnStation; + +public class BusFactory { + + protected static BusRouteEntity getBusRouteEntity(Long id) { + return BusRouteEntity.builder() + .id(id) + .apiRouteId("BRT" + id) + .routeName("7800" + id) + .routeTypeCd(BusRouteType.DIRECT_SEAT_CITY_BUS) + .routeTypeName(BusRouteType.DIRECT_SEAT_CITY_BUS.getName()) + .companyId("COMP123") + .companyName("수형운수") + .companyTel("02-123-4567") + .districtCd(DistrictCode.DONGDUCHEON) + .upFirstTime("05:30") + .upLastTime("23:00") + .downFirstTime("06:00") + .downLastTime("00:35") + .startMobileNo("101") + .startStationId(1001L) + .startStationName("기점 정류소") + .endStationId(2002L) + .endMobileNo("202") + .endStationName("종점 정류소") + .regionName("서울") + .peekAlloc(15) + .nPeekAlloc(25) + .build(); + } + + protected static BusRouteCreateDto getBusRouteCreateDto(Long id) { + + return BusRouteCreateDto.builder() + .apiRouteId("BRT" + id) + .routeName("7800") + .routeTypeCd(BusRouteType.DIRECT_SEAT_CITY_BUS) + .routeTypeName(BusRouteType.DIRECT_SEAT_CITY_BUS.getName()) + .companyId("COMP123") + .companyName("수형운수") + .companyTel("02-123-4567") + .districtCd(DistrictCode.DONGDUCHEON) + .upFirstTime("05:30") + .upLastTime("23:00") + .downFirstTime("06:00") + .downLastTime("00:35") + .startMobileNo("101") + .startStationId(1001L) + .startStationName("기점 정류소") + .endStationId(2002L) + .endMobileNo("202") + .endStationName("종점 정류소") + .regionName("서울") + .peekAlloc(15) + .nPeekAlloc(25) + .build(); + } + + protected static BusRouteRespDto getBusRouteRespDto(Long id) { + return BusRouteRespDto.builder() + .routeId(id) + .routeName("7800" + id) + .routeTypeCd(BusRouteType.DIRECT_SEAT_CITY_BUS) + .routeTypeName(BusRouteType.DIRECT_SEAT_CITY_BUS.getName()) + .districtCd(DistrictCode.DONGDUCHEON) + .upFirstTime("05:30") + .upLastTime("23:00") + .downFirstTime("06:00") + .downLastTime("00:35") + .startMobileNo("101") + .startStationId(1001L) + .startStationName("기점 정류소") + .endStationId(2002L) + .endMobileNo("202") + .endStationName("종점 정류소") + .regionName("서울") + .peekAlloc(15) + .nPeekAlloc(25) + .build(); + } + + protected static BusStationEntity getBusStationEntity(Long id) { + return BusStationEntity.builder() + .id(id) + .apiStationId("BST" + id) + .stationName("정거장" + id) + .regionName("서울") + .districtCd(DistrictCode.DONGDUCHEON) + .centerYn(CenterStation.CENTER_STATION) + .turnYn(TurnStation.TURN_STATION) + .longitude(BigDecimal.valueOf(127.123456)) + .latitude(BigDecimal.valueOf(37.123456)) + .build(); + } + + protected static BusStationCreateDto getBusStationCreateDto(Long id) { + return BusStationCreateDto.builder() + .apiStationId("BST" + id) + .stationName("정거장" + id) + .regionName("서울") + .districtCd(DistrictCode.DONGDUCHEON) + .centerYn(CenterStation.CENTER_STATION) + .turnYn(TurnStation.TURN_STATION) + .longitude(BigDecimal.valueOf(127.123456)) + .latitude(BigDecimal.valueOf(37.123456)) + .build(); + } + + protected static BusStationRespDto getBusStationRespDto(Long id) { + return BusStationRespDto.builder() + .stationId(id) + .stationName("정거장" + id) + .regionName("서울") + .districtCd(DistrictCode.DONGDUCHEON) + .centerYn(CenterStation.CENTER_STATION) + .turnYn(TurnStation.TURN_STATION) + .longitude(BigDecimal.valueOf(127.123456)) + .latitude(BigDecimal.valueOf(37.123456)) + .build(); + } + + protected static BusRouteStationEntity getBusRouteStationEntity(Long id, BusRouteEntity routeEntity, + BusStationEntity stationEntity) { + return BusRouteStationEntity.builder() + .id(id) + .route(routeEntity) + .station(stationEntity) + .stationName("정거장" + id) + .stationSeq(Short.valueOf(String.valueOf(id))) + .build(); + } + + protected static BusRouteStationCreateDto getBusRouteStationCreateDto(Long id) { + return BusRouteStationCreateDto.builder() + .apiRouteId("BRT" + id) + .apiStationId("BST" + id) + .stationName("정거장" + id) + .stationSeq(Short.valueOf(String.valueOf(id))) + .build(); + } + + protected static BusRouteStationRespDto getBusRouteStationRespDto(Long id, BusRouteRespDto routeRespDto, + BusStationRespDto stationRespDto) { + return BusRouteStationRespDto.builder() + .busRouteStationId(id) + .route(routeRespDto) + .station(stationRespDto) + .stationName("정거장" + id) + .stationSeq(Short.valueOf(String.valueOf(id))) + .build(); + } + +} diff --git a/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java b/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java index 6c6a5102..f3f735b7 100644 --- a/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java +++ b/server/src/test/java/com/talkka/server/bus/service/BusRouteServiceTest.java @@ -1,8 +1,12 @@ package com.talkka.server.bus.service; -import static org.assertj.core.api.AssertionsForClassTypes.*; +import static com.talkka.server.bus.service.BusFactory.*; +import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; +import java.util.List; +import java.util.Optional; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -15,8 +19,6 @@ import com.talkka.server.bus.dao.BusRouteRepository; import com.talkka.server.bus.dto.BusRouteCreateDto; import com.talkka.server.bus.dto.BusRouteRespDto; -import com.talkka.server.bus.enums.BusRouteType; -import com.talkka.server.bus.enums.DistrictCode; import com.talkka.server.common.exception.http.BadRequestException; @ExtendWith(MockitoExtension.class) @@ -28,88 +30,15 @@ public class BusRouteServiceTest { @Mock private BusRouteRepository busRouteRepository; - private BusRouteCreateDto getBusRouteReqDto(String id) { - - return BusRouteCreateDto.builder() - .apiRouteId(id) - .routeName("7800" + id) - .routeTypeCd(BusRouteType.DIRECT_SEAT_CITY_BUS) - .routeTypeName(BusRouteType.DIRECT_SEAT_CITY_BUS.getName()) - .companyId("COMP123") - .companyName("수형운수") - .companyTel("02-123-4567") - .districtCd(DistrictCode.DONGDUCHEON) - .upFirstTime("05:30") - .upLastTime("23:00") - .downFirstTime("06:00") - .downLastTime("00:35") - .startMobileNo("101") - .startStationId(1001L) - .startStationName("기점 정류소") - .endStationId(2002L) - .endMobileNo("202") - .endStationName("종점 정류소") - .regionName("서울") - .peekAlloc(15) - .nPeekAlloc(25) - .build(); - } - - private BusRouteRespDto getBusRouteRespDto(Long id) { - return BusRouteRespDto.builder() - .routeId(id) - .routeName("7800" + id) - .routeTypeCd(BusRouteType.DIRECT_SEAT_CITY_BUS) - .routeTypeName(BusRouteType.DIRECT_SEAT_CITY_BUS.getName()) - .districtCd(DistrictCode.DONGDUCHEON) - .upFirstTime("05:30") - .upLastTime("23:00") - .downFirstTime("06:00") - .downLastTime("00:35") - .startMobileNo("101") - .startStationId(1001L) - .startStationName("기점 정류소") - .endStationId(2002L) - .endMobileNo("202") - .endStationName("종점 정류소") - .regionName("서울") - .peekAlloc(15) - .nPeekAlloc(25) - .build(); - } - @Nested @DisplayName("createBusRoute method") public class CreateBusRouteTest { @Test void 버스_노선을_생성한다() { // given - BusRouteCreateDto busRouteCreateDto = getBusRouteReqDto("1"); + BusRouteCreateDto busRouteCreateDto = getBusRouteCreateDto(1L); BusRouteRespDto busRouteRespDto = getBusRouteRespDto(1L); - BusRouteEntity busRouteEntity = BusRouteEntity.builder() - .id(1L) - .apiRouteId(busRouteCreateDto.getApiRouteId()) - .routeName(busRouteCreateDto.getRouteName()) - .routeTypeCd(BusRouteType.DIRECT_SEAT_CITY_BUS) - .routeTypeName(BusRouteType.DIRECT_SEAT_CITY_BUS.getName()) - .companyId("COMP123") - .companyName("수형운수") - .companyTel("02-123-4567") - .districtCd(DistrictCode.DONGDUCHEON) - .upFirstTime("05:30") - .upLastTime("23:00") - .downFirstTime("06:00") - .downLastTime("00:35") - .startMobileNo("101") - .startStationId(1001L) - .startStationName("기점 정류소") - .endStationId(2002L) - .endMobileNo("202") - .endStationName("종점 정류소") - .regionName("서울") - .peekAlloc(15) - .nPeekAlloc(25) - .build(); + BusRouteEntity busRouteEntity = getBusRouteEntity(1L); given(busRouteRepository.save(any(BusRouteEntity.class))).willReturn(busRouteEntity); given(busRouteRepository.existsByApiRouteId(any(String.class))).willReturn(true); // when @@ -121,7 +50,7 @@ public class CreateBusRouteTest { @Test void 존재하는_버스_노선일_경우_Exception을_발생시킨다() { // given - BusRouteCreateDto reqDto = getBusRouteReqDto("1"); + BusRouteCreateDto reqDto = getBusRouteCreateDto(1L); given(busRouteRepository.existsByApiRouteId(any(String.class))).willReturn(false); // when // then @@ -131,4 +60,58 @@ public class CreateBusRouteTest { .hasMessage("이미 등록된 버스 노선입니다."); } } + + @Nested + @DisplayName("findByRouteId method") + public class FindByRouteIdTest { + @Test + void ID를_기반으로_버스_노선을_요청하면_레포지토리를_통해_결과를_DTO로_반환한다() { + // given + Long routeId = 1L; + BusRouteEntity foundEntity = getBusRouteEntity(routeId); + given(busRouteRepository.findById(anyLong())).willReturn(Optional.of(foundEntity)); + // when + var BusRouteRespDto = busRouteService.findByRouteId(routeId); + // then + verify(busRouteRepository).findById(anyLong()); + assertThat(BusRouteRespDto).isEqualTo(getBusRouteRespDto(routeId)); + } + + @Test + void ID가_존재하지_않으면_Exception을_throw한다() { + // given + Class exceptionClass = BadRequestException.class; + given(busRouteRepository.findById(anyLong())).willReturn(Optional.empty()); + // when + // then + assertThatThrownBy( + () -> busRouteService.findByRouteId(1L) + ).isInstanceOf(exceptionClass) + .hasMessage("존재하지 않는 노선입니다."); + verify(busRouteRepository, times(1)).findById(anyLong()); + } + } + + @Nested + @DisplayName("findByRouteName method") + public class FindByRouteNameTest { + + @Test + void 버스노선이름을_요청으로_받아_repository에서_조회하고_해당_이름으로_시작하는_노선들을_리스트로_반환한다() { + + // given + String routeName = "7800"; + var entityList = List.of(getBusRouteEntity(1L), getBusRouteEntity(2L)); + var expectedList = List.of(getBusRouteRespDto(1L), getBusRouteRespDto(2L)); + given(busRouteRepository.findByRouteNameLikeOrderByRouteNameAsc(any(String.class))).willReturn(entityList); + + // when + var resultList = busRouteService.findByRouteName(routeName); + + // then + verify(busRouteRepository, times(1)).findByRouteNameLikeOrderByRouteNameAsc(anyString()); + assertThat(resultList).containsAll(expectedList); + + } + } } diff --git a/server/src/test/java/com/talkka/server/bus/service/BusRouteStationServiceTest.java b/server/src/test/java/com/talkka/server/bus/service/BusRouteStationServiceTest.java new file mode 100644 index 00000000..5c319b7d --- /dev/null +++ b/server/src/test/java/com/talkka/server/bus/service/BusRouteStationServiceTest.java @@ -0,0 +1,171 @@ +package com.talkka.server.bus.service; + +import static com.talkka.server.bus.service.BusFactory.*; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.BDDMockito.*; + +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.talkka.server.bus.dao.BusRouteRepository; +import com.talkka.server.bus.dao.BusRouteStationEntity; +import com.talkka.server.bus.dao.BusRouteStationRepository; +import com.talkka.server.bus.dao.BusStationRepository; +import com.talkka.server.common.exception.http.BadRequestException; + +@ExtendWith(MockitoExtension.class) +public class BusRouteStationServiceTest { + + @InjectMocks + BusRouteStationService routeStationService; + + @Mock + private BusRouteRepository routeRepository; + @Mock + private BusStationRepository stationRepository; + @Mock + private BusRouteStationRepository routeStationRepository; + + @Nested + @DisplayName("createBusStation method") + public class CreateBusStationTest { + @Test + void BusRouteStationReqDto를_요청으로_받아_BusRouteStationRepository에_저장한다() { + /// given + Long id = 1L; + var createDto = getBusRouteStationCreateDto(id); + var expected = getBusRouteStationRespDto(id, getBusRouteRespDto(id), getBusStationRespDto(id)); + given(routeRepository.findByApiRouteId(any(String.class))).willReturn(Optional.of(getBusRouteEntity(id))); + given(stationRepository.findByApiStationId(any(String.class))).willReturn( + Optional.of(getBusStationEntity(id))); + given(routeStationRepository.save(any(BusRouteStationEntity.class))).willReturn( + getBusRouteStationEntity(id, getBusRouteEntity(id), getBusStationEntity(id))); + // when + var result = routeStationService.createBusRouteStation(createDto); + // then + assertThat(result).isEqualTo(expected); + } + + @Test + void 존재하지_않는_Route면_Exception을_발생시킨다() { + // given + var createDto = getBusRouteStationCreateDto(1L); + given(routeRepository.findByApiRouteId(any())).willReturn(Optional.empty()); + // when + // then + assertThatThrownBy(() -> routeStationService.createBusRouteStation(createDto)).isInstanceOf( + BadRequestException.class).hasMessage("존재하지 않는 노선입니다."); + } + + @Test + void 존재하지_않는_Station이면_Exception을_발생시킨다() { + // given + var createDto = getBusRouteStationCreateDto(1L); + given(routeRepository.findByApiRouteId(any())).willReturn(Optional.of(getBusRouteEntity(1L))); + given(stationRepository.findByApiStationId(any())).willReturn(Optional.empty()); + // when + // then + assertThatThrownBy(() -> routeStationService.createBusRouteStation(createDto)).isInstanceOf( + BadRequestException.class).hasMessage("존재하지 않는 정류장입니다."); + } + } + + @Nested + @DisplayName("findById method") + public class FindByIdTest { + + @Test + void Id를_받아_해당되는_정류장노선_정보를_조회하고_결과를_RespDto로_반환한다() { + // given + Long id = 1L; + var expected = getBusRouteStationRespDto(id, getBusRouteRespDto(id), getBusStationRespDto(id)); + given(routeStationRepository.findById(any(Long.class))).willReturn( + Optional.of(getBusRouteStationEntity(id, getBusRouteEntity(id), getBusStationEntity(id)))); + // when + var result = routeStationService.findById(id); + // then + assertThat(result).isEqualTo(expected); + } + + @Test + void 존재하지_않는_Id면_Exception을_throw한다() { + // given + Long id = 1L; + given(routeStationRepository.findById(anyLong())).willReturn(Optional.empty()); + // when + + // then + assertThatThrownBy(() -> routeStationService.findById(id)).isInstanceOf(BadRequestException.class) + .hasMessage("존재하지 않는 노선정류장입니다."); + } + } + + @Nested + @DisplayName("findByRouteId method") + public class FindByRouteIdTest { + + @Test + void RouteId를_받아_해당노선에_속하는_정류장정보를_조회하고_결과를_RespDto의_리스트로_반환한다() { + // given + Long routeId = 1L; + Long id1 = 2L; + Long id2 = 3L; + Long id3 = 4L; + var expected = List.of( + getBusRouteStationRespDto(id1, getBusRouteRespDto(routeId), getBusStationRespDto(id1)), + getBusRouteStationRespDto(id2, getBusRouteRespDto(routeId), getBusStationRespDto(id2)), + getBusRouteStationRespDto(id3, getBusRouteRespDto(routeId), getBusStationRespDto(id3)) + ); + given(routeStationRepository.findByRouteId(any(Long.class))).willReturn( + List.of( + getBusRouteStationEntity(id1, getBusRouteEntity(routeId), getBusStationEntity(id1)), + getBusRouteStationEntity(id2, getBusRouteEntity(routeId), getBusStationEntity(id2)), + getBusRouteStationEntity(id3, getBusRouteEntity(routeId), getBusStationEntity(id3)) + ) + ); + // when + var result = routeStationService.findByRouteId(routeId); + // then + assertThat(result).isEqualTo(expected); + } + } + + @Nested + @DisplayName("findByStationId method") + public class FindByStationIdTest { + + @Test + void StationId를_받아_해당노선에_속하는_정류장정보를_조회하고_결과를_RespDto의_리스트로_반환한다() { + // given + Long stationId = 1L; + Long id1 = 2L; + Long id2 = 3L; + Long id3 = 4L; + var expected = List.of( + getBusRouteStationRespDto(id1, getBusRouteRespDto(id1), getBusStationRespDto(stationId)), + getBusRouteStationRespDto(id2, getBusRouteRespDto(id2), getBusStationRespDto(stationId)), + getBusRouteStationRespDto(id3, getBusRouteRespDto(id3), getBusStationRespDto(stationId)) + ); + given(routeStationRepository.findByStationId(any(Long.class))).willReturn( + List.of( + getBusRouteStationEntity(id1, getBusRouteEntity(id1), getBusStationEntity(stationId)), + getBusRouteStationEntity(id2, getBusRouteEntity(id2), getBusStationEntity(stationId)), + getBusRouteStationEntity(id3, getBusRouteEntity(id3), getBusStationEntity(stationId)) + ) + ); + // when + var result = routeStationService.findByStationId(stationId); + // then + assertThat(result).isEqualTo(expected); + } + } +} diff --git a/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java b/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java new file mode 100644 index 00000000..54cae989 --- /dev/null +++ b/server/src/test/java/com/talkka/server/bus/service/BusStationServiceTest.java @@ -0,0 +1,115 @@ +package com.talkka.server.bus.service; + +import static com.talkka.server.bus.service.BusFactory.*; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.talkka.server.bus.dao.BusStationEntity; +import com.talkka.server.bus.dao.BusStationRepository; +import com.talkka.server.bus.dto.BusStationCreateDto; +import com.talkka.server.bus.dto.BusStationRespDto; +import com.talkka.server.common.exception.http.BadRequestException; + +@ExtendWith(MockitoExtension.class) +class BusStationServiceTest { + @InjectMocks + private BusStationService busStationService; + + @Mock + private BusStationRepository busStationRepository; + + @Nested + @DisplayName("findByStationId method") + public class FindByStationId { + @Test + void ID를_기반으로_버스_정류장을_요청하면_레포지토리를_통해_조회하여_결과를_DTO로_반환한다() { + Long stationId = 1L; + BusStationEntity busStationEntity = getBusStationEntity(stationId); + BusStationRespDto expected = getBusStationRespDto(stationId); + given(busStationRepository.findById(stationId)).willReturn(Optional.of(busStationEntity)); + // when + BusStationRespDto result = busStationService.findByStationId(stationId); + // then + verify(busStationRepository, times(1)).findById(anyLong()); + assertThat(result).isEqualTo(expected); + } + + @Test + void ID가_존재하지_않으면_Exception을_throw한다() { + // given + Long stationId = 1L; + Class exceptionCLass = BadRequestException.class; + given(busStationRepository.findById(anyLong())).willReturn(Optional.empty()); + // when + // then + assertThatThrownBy( + () -> busStationService.findByStationId(stationId) + ).isInstanceOf(exceptionCLass) + .hasMessage("존재하지 않는 정거장입니다."); + verify(busStationRepository, times(1)).findById(anyLong()); + } + } + + @Nested + @DisplayName("createBusStation method") + public class CreateBusStationTest { + @Test + void BusStationReqDto를_요청으로_받아_BusStationRepository에_저장한다() { + // given + BusStationCreateDto createDto = getBusStationCreateDto(1L); + given(busStationRepository.save(any(BusStationEntity.class))).willReturn(getBusStationEntity(1L)); + // when + var result = busStationService.createBusStation(createDto); + // then + verify(busStationRepository, times(1)).save(any(BusStationEntity.class)); + assertThat(result).isEqualTo(getBusStationRespDto(1L)); + } + + @Test + void 이미_등록된_정거장일_경우_Exception을_발생시킨다() { + // given + var createDto = getBusStationCreateDto(1L); + Class exceptionClass = BadRequestException.class; + given(busStationRepository.existsByApiStationId(createDto.getApiStationId())).willReturn(true); + // when + // then + assertThatThrownBy(() -> busStationService.createBusStation(createDto)) + .isInstanceOf(exceptionClass).hasMessage("이미 등록된 정거장입니다."); + } + } + + @Nested + @DisplayName("findByStationName method") + public class FindByStationNameTest { + @Test + void 정류장_이름으로_요청하면_해당_이름으로_시작하는_정류장의_리스트를_반환한다() { + // given + String stationName = "정거장1"; + List expected = List.of( + getBusStationRespDto(1L), + getBusStationRespDto(12L) + ); + List entityList = List.of( + getBusStationEntity(1L), + getBusStationEntity(12L) + ); + given(busStationRepository.findByStationNameLikeOrderByStationNameAsc(anyString())).willReturn(entityList); + // when + var result = busStationService.findByStationName(stationName); + // then + assertThat(result).containsAll(expected); + verify(busStationRepository, times(1)).findByStationNameLikeOrderByStationNameAsc(anyString()); + } + } +} \ No newline at end of file