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