@Test public void testGetLocationListByRegion() { var regionEntity = new RegionEntity(); regionEntity.setRegionId(1); regionEntity.setRegionName("地域1"); given(regionRepository.findById(1)).willReturn(Optional.of(regionEntity)); var loc1 = new LocationEntity(); loc1.setLocationId(1L); loc1.setLocationName("地点1"); loc1.setRegion(regionEntity); loc1.setNote("地点1の詳細です。"); var loc2 = new LocationEntity(); loc2.setLocationId(1L); loc2.setLocationName("地点2"); loc2.setRegion(regionEntity); loc2.setNote("地点2の詳細です。"); var locationList = List.of(loc1, loc2); given(locationRepository.findByRegion(regionEntity)).willReturn(locationList); var result = api.getLocationListByRegion(1); assertThat(result.getLocationList()).hasSize(2); }
@GetMapping(value = "region/{regionId}", produces = MediaType.APPLICATION_JSON_VALUE) public LocationsDto getLocationListByRegion(@PathVariable("regionId") Integer regionId) { LOGGER.info("LOCATION LIST BY REGION ID API"); var locationList = service.getLocationListByRegionId(regionId); var dtoList = new ArrayList<LocationDto>(); locationList.forEach(location -> { var dto = new LocationDto(location); dtoList.add(dto); }); var locationsDto = new LocationsDto(dtoList); return locationsDto; }
LocationApi { @GetMapping(value = "region/{regionId}", produces = MediaType.APPLICATION_JSON_VALUE) public LocationsDto getLocationListByRegion(@PathVariable("regionId") Integer regionId) { LOGGER.info("LOCATION LIST BY REGION ID API"); var locationList = service.getLocationListByRegionId(regionId); var dtoList = new ArrayList<LocationDto>(); locationList.forEach(location -> { var dto = new LocationDto(location); dtoList.add(dto); }); var locationsDto = new LocationsDto(dtoList); return locationsDto; } }
LocationApi { @GetMapping(value = "region/{regionId}", produces = MediaType.APPLICATION_JSON_VALUE) public LocationsDto getLocationListByRegion(@PathVariable("regionId") Integer regionId) { LOGGER.info("LOCATION LIST BY REGION ID API"); var locationList = service.getLocationListByRegionId(regionId); var dtoList = new ArrayList<LocationDto>(); locationList.forEach(location -> { var dto = new LocationDto(location); dtoList.add(dto); }); var locationsDto = new LocationsDto(dtoList); return locationsDto; }  }
LocationApi { @GetMapping(value = "region/{regionId}", produces = MediaType.APPLICATION_JSON_VALUE) public LocationsDto getLocationListByRegion(@PathVariable("regionId") Integer regionId) { LOGGER.info("LOCATION LIST BY REGION ID API"); var locationList = service.getLocationListByRegionId(regionId); var dtoList = new ArrayList<LocationDto>(); locationList.forEach(location -> { var dto = new LocationDto(location); dtoList.add(dto); }); var locationsDto = new LocationsDto(dtoList); return locationsDto; }  @GetMapping(value = "region/{regionId}", produces = MediaType.APPLICATION_JSON_VALUE) LocationsDto getLocationListByRegion(@PathVariable("regionId") Integer regionId); }
LocationApi { @GetMapping(value = "region/{regionId}", produces = MediaType.APPLICATION_JSON_VALUE) public LocationsDto getLocationListByRegion(@PathVariable("regionId") Integer regionId) { LOGGER.info("LOCATION LIST BY REGION ID API"); var locationList = service.getLocationListByRegionId(regionId); var dtoList = new ArrayList<LocationDto>(); locationList.forEach(location -> { var dto = new LocationDto(location); dtoList.add(dto); }); var locationsDto = new LocationsDto(dtoList); return locationsDto; }  @GetMapping(value = "region/{regionId}", produces = MediaType.APPLICATION_JSON_VALUE) LocationsDto getLocationListByRegion(@PathVariable("regionId") Integer regionId);  }