@Test public void getAndSetBooleanPreference_correctlyGetsPreferenceFromDefault() throws Exception { when(sharedPreferences.contains(TEST_PREFERENCE)).thenReturn(false); assertThat(sharedPreferencesUtils.getAndSetBooleanPreference(TEST_PREFERENCE, true)).isTrue(); verify(sharedPreferences).contains(TEST_PREFERENCE); verify(editor).putBoolean(TEST_PREFERENCE, true); verify(editor).apply(); }
public boolean getAndSetBooleanPreference(String preference, boolean defaultValue) { Application application = (Application) firebaseApp.getApplicationContext(); SharedPreferences preferences = application.getSharedPreferences(PREFERENCES_PACKAGE_NAME, Context.MODE_PRIVATE); if (preferences.contains(preference)) { boolean result = preferences.getBoolean(preference, defaultValue); return result; } setBooleanPreference(preference, defaultValue); return defaultValue; }
SharedPreferencesUtils { public boolean getAndSetBooleanPreference(String preference, boolean defaultValue) { Application application = (Application) firebaseApp.getApplicationContext(); SharedPreferences preferences = application.getSharedPreferences(PREFERENCES_PACKAGE_NAME, Context.MODE_PRIVATE); if (preferences.contains(preference)) { boolean result = preferences.getBoolean(preference, defaultValue); return result; } setBooleanPreference(preference, defaultValue); return defaultValue; } }
SharedPreferencesUtils { public boolean getAndSetBooleanPreference(String preference, boolean defaultValue) { Application application = (Application) firebaseApp.getApplicationContext(); SharedPreferences preferences = application.getSharedPreferences(PREFERENCES_PACKAGE_NAME, Context.MODE_PRIVATE); if (preferences.contains(preference)) { boolean result = preferences.getBoolean(preference, defaultValue); return result; } setBooleanPreference(preference, defaultValue); return defaultValue; } @Inject  SharedPreferencesUtils(FirebaseApp firebaseApp); }
SharedPreferencesUtils { public boolean getAndSetBooleanPreference(String preference, boolean defaultValue) { Application application = (Application) firebaseApp.getApplicationContext(); SharedPreferences preferences = application.getSharedPreferences(PREFERENCES_PACKAGE_NAME, Context.MODE_PRIVATE); if (preferences.contains(preference)) { boolean result = preferences.getBoolean(preference, defaultValue); return result; } setBooleanPreference(preference, defaultValue); return defaultValue; } @Inject  SharedPreferencesUtils(FirebaseApp firebaseApp); void setBooleanPreference(String preference, boolean value); void clearPreference(String preference); boolean getAndSetBooleanPreference(String preference, boolean defaultValue); boolean getBooleanPreference(String preference, boolean defaultValue); boolean isPreferenceSet(String preference); boolean isManifestSet(String preference); boolean getBooleanManifestValue(String preference, boolean defaultValue); }
SharedPreferencesUtils { public boolean getAndSetBooleanPreference(String preference, boolean defaultValue) { Application application = (Application) firebaseApp.getApplicationContext(); SharedPreferences preferences = application.getSharedPreferences(PREFERENCES_PACKAGE_NAME, Context.MODE_PRIVATE); if (preferences.contains(preference)) { boolean result = preferences.getBoolean(preference, defaultValue); return result; } setBooleanPreference(preference, defaultValue); return defaultValue; } @Inject  SharedPreferencesUtils(FirebaseApp firebaseApp); void setBooleanPreference(String preference, boolean value); void clearPreference(String preference); boolean getAndSetBooleanPreference(String preference, boolean defaultValue); boolean getBooleanPreference(String preference, boolean defaultValue); boolean isPreferenceSet(String preference); boolean isManifestSet(String preference); boolean getBooleanManifestValue(String preference, boolean defaultValue);  }