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