ServicesManager implements DataSource { @Override public Observable<List<CityEntity>> getCityEntities() { return weatherInfoService.getCityInfos(Constants.CITY_LIST_URL) .map(new Func1<String, List<CityEntity>>() { @Override public List<CityEntity> call(String citysResponse) { if (TextUtils.isEmpty(citysResponse)) { throw new WeatherServiceException("no data"); } mCityEntities.clear(); BufferedReader reader = null; try { reader = new BufferedReader(new StringReader(citysResponse)); String tempString; while ((tempString = reader.readLine()) != null) { if (tempString.startsWith(Constants.CITY_LIST_LINE_HEADER) || tempString.startsWith(Constants.CITY_LIST_LINE_HEADER_1)) { tempString = tempString.replace("|", ""); tempString = tempString.trim(); String [] cityFileds = tempString.split("\\s+"); if (cityFileds.length >= Constants.CITY_LIST_FIELD_NUM) { CityEntity cityEntity = new CityEntity(); cityEntity.setCityId(TextUtils.isEmpty(cityFileds[Constants.CITY_LIST_FIELD_ID]) ? CityEntity.DEFAULT_VALUE : cityFileds[Constants.CITY_LIST_FIELD_ID]); cityEntity.setCountry(TextUtils.isEmpty(cityFileds[Constants.CITY_LIST_FIELD_COUNTY]) ? CityEntity.DEFAULT_VALUE : cityFileds[Constants.CITY_LIST_FIELD_COUNTY]); cityEntity.setProvince(TextUtils.isEmpty(cityFileds[Constants.CITY_LIST_FIELD_PROVINCE]) ? CityEntity.DEFAULT_VALUE : cityFileds[Constants.CITY_LIST_FIELD_PROVINCE]); cityEntity.setCity(TextUtils.isEmpty(cityFileds[Constants.CITY_LIST_FIELD_CITY]) ? CityEntity.DEFAULT_VALUE : cityFileds[Constants.CITY_LIST_FIELD_CITY]); mCityEntities.add(cityEntity); } } } } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } return mCityEntities; } }); } private  ServicesManager(); static ServicesManager getInstance(); @Override void clear(); @Override Observable<List<CityEntity>> getCityEntities(); @Override Observable<List<WeatherConditionEntity>> getWeatherConditionEntities(); @Override Observable<WeatherEntity> getCityWeather(String cityId, boolean fromCache);  }
@Test public void testServicesManagerGetCitys() throws Exception { assertNotNull(mServicesManger); TestSubscriber<List<CityEntity>> testSubscriber = TestSubscriber.create(new GetCitysDelegate()); mServicesManger.getCityEntities().subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); testSubscriber.assertNoErrors(); }