### Question:
FloatPreference extends AbsPreference<Float> { @Override public void set(Float value) { if (value == null) throw new NullPointerException("value"); this.set((float)value); } FloatPreference(SharedPreferences preferences, String key);  FloatPreference(SharedPreferences preferences, String key, float defaultValue); @Override Float get(); @Override void set(Float value); @SuppressLint("CommitPrefEdits") void set(float value);  }### Answer:
@Test public void saveFloat() { float expected = 10f; String key = "testKey"; FloatPreference preference = new FloatPreference(preferences, key); preference.set(expected); assertThat(preferences.getFloat(key, 0)).isEqualTo(expected); }
@Test public void throwWhenSetWithNull() { String key = "testKey1"; FloatPreference preference = new FloatPreference(preferences, key); try { preference.set(null); } catch (NullPointerException e) { return; } throw new AssertionError("Calling 'set' with null did not throw"); }