Preference { public T asValue() { return proxy.get(key, defValue, preferences); } Preference(SharedPreferences preferences, final String key, T defValue, Proxy<T> proxy, Observable<String> keyChanges); T asValue(); Observable<T> asObservable(); Action1<? super T> asAction();  }
@Test public void getDefaultValue() { assertThat(rxPreferences.getBoolean("key1", false).asValue()).isFalse(); assertThat(rxPreferences.getFloat("key2", 0F).asValue()).isZero(); assertThat(rxPreferences.getInt("key3", 0).asValue()).isZero(); assertThat(rxPreferences.getLong("key4", 0L).asValue()).isZero(); assertThat(rxPreferences.getString("key5", null).asValue()).isNull(); assertThat(rxPreferences.getStringSet("key6", null).asValue()).isNull(); }
@Test public void getStoredValue() { preferences.edit().putBoolean("key1", true).commit(); assertThat(rxPreferences.getBoolean("key1", false).asValue()).isEqualTo(true); preferences.edit().putFloat("key2", 1).commit(); assertThat(rxPreferences.getFloat("key2", 0).asValue()).isEqualTo(1); preferences.edit().putInt("key3", 1).commit(); assertThat(rxPreferences.getInt("key3", 0).asValue()).isEqualTo(1); preferences.edit().putLong("key4", 1).commit(); assertThat(rxPreferences.getLong("key4", 0).asValue()).isEqualTo(1); preferences.edit().putString("key5", "value").commit(); assertThat(rxPreferences.getString("key5", null).asValue()).isEqualTo("value"); preferences.edit().putStringSet("key6", singleton("value")).commit(); assertThat(rxPreferences.getStringSet("key6", null).asValue()).isEqualTo(singleton("value")); }
@Test public void putValue() { rxPreferences.putBoolean("key1", true); assertThat(rxPreferences.getBoolean("key1", false).asValue()).isEqualTo(true); rxPreferences.putFloat("key2", 1); assertThat(rxPreferences.getFloat("key2", 0).asValue()).isEqualTo(1); rxPreferences.putInt("key3", 1); assertThat(rxPreferences.getInt("key3", 0).asValue()).isEqualTo(1); rxPreferences.putLong("key4", 1); assertThat(rxPreferences.getLong("key4", 0).asValue()).isEqualTo(1); rxPreferences.putString("key5", "value"); assertThat(rxPreferences.getString("key5", null).asValue()).isEqualTo("value"); rxPreferences.putStringSet("key6", singleton("value")); assertThat(rxPreferences.getStringSet("key6", null).asValue()).isEqualTo(singleton("value")); }