### Question:
BooleanPreference extends AbsPreference<Boolean> { @Override public void set(Boolean value) { if (value == null) throw new NullPointerException("value"); this.set((boolean) value); } BooleanPreference(SharedPreferences preferences, String key);  BooleanPreference(SharedPreferences preferences, String key, boolean defaultValue); @Override Boolean get(); @Override void set(Boolean value); @SuppressLint("CommitPrefEdits") void set(boolean value);  }### Answer:
@Test public void saveBoolean() { boolean expected = true; String key = "testKey"; BooleanPreference preference = new BooleanPreference(preferences, key); preference.set(expected); assertThat(preferences.getBoolean(key, false)).isTrue(); }
@Test public void throwWhenSetWithNull() { String key = "testKey1"; BooleanPreference preference = new BooleanPreference(preferences, key); try { preference.set(null); } catch (NullPointerException e) { return; } throw new AssertionError("Calling 'set' with null did not throw"); }