@Test public void testOnChangeListenerCallbackWithNotPreferenceKey() { final SharedPreference.PreferenceChangeCallback<String> mockCallback = mock(PreferenceChangeStringCallback.class); final SharedPreference<String> preference = new PreferenceImpl(PREF_KEY, PREF_DEF_VALUE); final SharedPreferences.OnSharedPreferenceChangeListener listener = preference.createOnChangeListener(mockCallback); listener.onSharedPreferenceChanged(preferences, "NotPreferenceKey"); verify(mockCallback, times(0)).onPreferenceChanged(preference); }
@NonNull public SharedPreferences.OnSharedPreferenceChangeListener createOnChangeListener(@NonNull final PreferenceChangeCallback<T> callback) { return new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(@NonNull final SharedPreferences sharedPreferences, @NonNull final String key) { if (SharedPreference.this.key.equals(key)) { valueIsActual = false; getFromPreferences(sharedPreferences); callback.onPreferenceChanged(SharedPreference.this); } } }; }
SharedPreference { @NonNull public SharedPreferences.OnSharedPreferenceChangeListener createOnChangeListener(@NonNull final PreferenceChangeCallback<T> callback) { return new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(@NonNull final SharedPreferences sharedPreferences, @NonNull final String key) { if (SharedPreference.this.key.equals(key)) { valueIsActual = false; getFromPreferences(sharedPreferences); callback.onPreferenceChanged(SharedPreference.this); } } }; } }
SharedPreference { @NonNull public SharedPreferences.OnSharedPreferenceChangeListener createOnChangeListener(@NonNull final PreferenceChangeCallback<T> callback) { return new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(@NonNull final SharedPreferences sharedPreferences, @NonNull final String key) { if (SharedPreference.this.key.equals(key)) { valueIsActual = false; getFromPreferences(sharedPreferences); callback.onPreferenceChanged(SharedPreference.this); } } }; } protected  SharedPreference(@NonNull final String key, @Nullable final T defValue); }
SharedPreference { @NonNull public SharedPreferences.OnSharedPreferenceChangeListener createOnChangeListener(@NonNull final PreferenceChangeCallback<T> callback) { return new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(@NonNull final SharedPreferences sharedPreferences, @NonNull final String key) { if (SharedPreference.this.key.equals(key)) { valueIsActual = false; getFromPreferences(sharedPreferences); callback.onPreferenceChanged(SharedPreference.this); } } }; } protected  SharedPreference(@NonNull final String key, @Nullable final T defValue); @NonNull final String getKey(); @NonNull SharedPreferences.OnSharedPreferenceChangeListener createOnChangeListener(@NonNull final PreferenceChangeCallback<T> callback); @Nullable final T getDefaultValue(); SharedPreference<T> updateValue(@Nullable final T newValue); final boolean putIntoPreferences(@NonNull final SharedPreferences preferences); @Nullable final T getValue(); }
SharedPreference { @NonNull public SharedPreferences.OnSharedPreferenceChangeListener createOnChangeListener(@NonNull final PreferenceChangeCallback<T> callback) { return new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(@NonNull final SharedPreferences sharedPreferences, @NonNull final String key) { if (SharedPreference.this.key.equals(key)) { valueIsActual = false; getFromPreferences(sharedPreferences); callback.onPreferenceChanged(SharedPreference.this); } } }; } protected  SharedPreference(@NonNull final String key, @Nullable final T defValue); @NonNull final String getKey(); @NonNull SharedPreferences.OnSharedPreferenceChangeListener createOnChangeListener(@NonNull final PreferenceChangeCallback<T> callback); @Nullable final T getDefaultValue(); SharedPreference<T> updateValue(@Nullable final T newValue); final boolean putIntoPreferences(@NonNull final SharedPreferences preferences); @Nullable final T getValue();  }