@Test public void test_should_fetch_city_for_given_code() { final org.egov.boundary.web.contract.City cityContract = org.egov.boundary.web.contract.City.builder() .code("0001").tenantId("tenantId").build(); final CityRequest cityRequestForCityCode = CityRequest.builder().city(cityContract).build(); when(cityRepository.findByCodeAndTenantId(cityRequestForCityCode.getCity().getCode(), cityRequestForCityCode.getCity().getTenantId())).thenReturn(getExpectedCityDetails()); City city = cityService.getCityByCityReq(cityRequestForCityCode); assertEquals("0001", city.getCode()); }
public City getCityByCityReq(CityRequest cityRequest) { City city = new City(); if (cityRequest.getCity().getId() != null) { city = (cityRepository.findByIdAndTenantId(Long.valueOf(cityRequest.getCity().getId()),cityRequest.getCity().getTenantId())); } else if (!StringUtils.isEmpty(cityRequest.getCity().getCode())) { city = (cityRepository.findByCodeAndTenantId(cityRequest.getCity().getCode(),cityRequest.getCity().getTenantId())); } return city; }
CityService { public City getCityByCityReq(CityRequest cityRequest) { City city = new City(); if (cityRequest.getCity().getId() != null) { city = (cityRepository.findByIdAndTenantId(Long.valueOf(cityRequest.getCity().getId()),cityRequest.getCity().getTenantId())); } else if (!StringUtils.isEmpty(cityRequest.getCity().getCode())) { city = (cityRepository.findByCodeAndTenantId(cityRequest.getCity().getCode(),cityRequest.getCity().getTenantId())); } return city; } }
CityService { public City getCityByCityReq(CityRequest cityRequest) { City city = new City(); if (cityRequest.getCity().getId() != null) { city = (cityRepository.findByIdAndTenantId(Long.valueOf(cityRequest.getCity().getId()),cityRequest.getCity().getTenantId())); } else if (!StringUtils.isEmpty(cityRequest.getCity().getCode())) { city = (cityRepository.findByCodeAndTenantId(cityRequest.getCity().getCode(),cityRequest.getCity().getTenantId())); } return city; } @Autowired  CityService(final CityRepository cityRepository); }
CityService { public City getCityByCityReq(CityRequest cityRequest) { City city = new City(); if (cityRequest.getCity().getId() != null) { city = (cityRepository.findByIdAndTenantId(Long.valueOf(cityRequest.getCity().getId()),cityRequest.getCity().getTenantId())); } else if (!StringUtils.isEmpty(cityRequest.getCity().getCode())) { city = (cityRepository.findByCodeAndTenantId(cityRequest.getCity().getCode(),cityRequest.getCity().getTenantId())); } return city; } @Autowired  CityService(final CityRepository cityRepository); City getCityByCityReq(CityRequest cityRequest); }
CityService { public City getCityByCityReq(CityRequest cityRequest) { City city = new City(); if (cityRequest.getCity().getId() != null) { city = (cityRepository.findByIdAndTenantId(Long.valueOf(cityRequest.getCity().getId()),cityRequest.getCity().getTenantId())); } else if (!StringUtils.isEmpty(cityRequest.getCity().getCode())) { city = (cityRepository.findByCodeAndTenantId(cityRequest.getCity().getCode(),cityRequest.getCity().getTenantId())); } return city; } @Autowired  CityService(final CityRepository cityRepository); City getCityByCityReq(CityRequest cityRequest);  }