@Test public void put_placesKeyValuePairIntoSharedPrefs() { when( sharedPreferencesEditor.putString(anyString(), anyString()) ).thenReturn(sharedPreferencesEditor); PersistentStore.put("key", "value", context); InOrder inOrder = Mockito.inOrder(sharedPreferencesEditor); inOrder.verify(sharedPreferencesEditor).putString("key", "value"); inOrder.verify(sharedPreferencesEditor).apply(); }
static void put(String key, String value, Context context) { Context applicationContext = context.getApplicationContext(); SharedPreferences sharedPreferences = applicationContext.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE); sharedPreferences.edit().putString(key, value).apply(); }
PersistentStore { static void put(String key, String value, Context context) { Context applicationContext = context.getApplicationContext(); SharedPreferences sharedPreferences = applicationContext.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE); sharedPreferences.edit().putString(key, value).apply(); } }
PersistentStore { static void put(String key, String value, Context context) { Context applicationContext = context.getApplicationContext(); SharedPreferences sharedPreferences = applicationContext.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE); sharedPreferences.edit().putString(key, value).apply(); }  }
PersistentStore { static void put(String key, String value, Context context) { Context applicationContext = context.getApplicationContext(); SharedPreferences sharedPreferences = applicationContext.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE); sharedPreferences.edit().putString(key, value).apply(); }   }
PersistentStore { static void put(String key, String value, Context context) { Context applicationContext = context.getApplicationContext(); SharedPreferences sharedPreferences = applicationContext.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE); sharedPreferences.edit().putString(key, value).apply(); }    }