### Question:
StringPreference extends AbsPreference<String> { @SuppressLint("CommitPrefEdits") @Override public void set(String value) { Editor editor = getPreferences().edit().putString(getKey(), value); PREF_SAVER.save(editor); } StringPreference(SharedPreferences preferences, String key);  StringPreference(SharedPreferences preferences, String key, String defaultValue); @Override String get(); @SuppressLint("CommitPrefEdits") @Override void set(String value);  }### Answer:
@Test public void saveString() { String expected = "Test"; String key = "testKey"; StringPreference preference = new StringPreference(preferences, key); preference.set(expected); assertThat(preferences.getString(key, null)).isEqualTo(expected); }
@Test public void setWithNull() { String key = "testKey1"; StringPreference preference = new StringPreference(preferences, key); preference.set(null); assertThat(preferences.getString(key, null)).isNull(); }