Preferences { public void setFavoriteCity(City city) { mPrefs.edit() .putString(KEY_FAV_CITY_LAT, city.lat.toString()) .putString(KEY_FAV_CITY_LNG, city.lng.toString()) .apply(); keepInMemory(city); } @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_save_favorite_city_coordinates_in_prefs_and_object_in_memory() { City city = new City(); city.lat = 10.5d; city.lng = 20.4d; prefs.setFavoriteCity(city); assertThat(prefs.mCity).isSameAs(city); assertThat(sharedPrefs.getString(KEY_FAV_CITY_LAT, null)).isEqualTo("10.5"); assertThat(sharedPrefs.getString(KEY_FAV_CITY_LNG, null)).isEqualTo("20.4"); }