Preferences { public Pair<String, String> getFavoriteCityLatLng() { String lat = mPrefs.getString(KEY_FAV_CITY_LAT, null); String lng = mPrefs.getString(KEY_FAV_CITY_LNG, null); if (lat == null || lng == null) { return null; } return Pair.create(lat, lng); } @Inject  Preferences(Application app); long getLastDownloadDate(); void setDownloadDate(); Pair<String, String> getFavoriteCityLatLng(); void setFavoriteCity(City city); void reset(); void keepInMemory(City city); City getCity(); boolean isUsingHrMode(); void toggleMode(); boolean shouldResetData(); static final String PREFS_NAME; }
@Test public void should_create_a_pair_of_lat_lng_when_getting_favorite_city() { sharedPrefs.edit().putString(KEY_FAV_CITY_LAT, "42").putString(KEY_FAV_CITY_LNG, "24").commit(); Pair<String, String> result = prefs.getFavoriteCityLatLng(); assertThat(result.first).isEqualTo("42"); assertThat(result.second).isEqualTo("24"); }
@Test public void should_return_null_if_lat_or_lng_is_missing() { sharedPrefs.edit().remove(KEY_FAV_CITY_LAT).putString(KEY_FAV_CITY_LNG, "24").commit(); Pair<String, String> result = prefs.getFavoriteCityLatLng(); assertThat(result).isNull(); }