BooleanPreference extends BasePreference<Boolean> { public static BooleanPreference newInstance(@NonNull SharedPreferences preferences, @NonNull String key, boolean defaultValue) { return newInstance(preferences, key, defaultValue, false); } private  BooleanPreference(@NonNull SharedPreferences sharedPreferences, @NonNull String key,
      boolean defaultValue, boolean commit); static BooleanPreference newInstance(@NonNull SharedPreferences preferences,
      @NonNull String key, boolean defaultValue); static BooleanPreference newInstance(@NonNull SharedPreferences preferences,
      @NonNull String key, boolean defaultValue, boolean commit); @SuppressWarnings("ConstantConditions") @Override Boolean get();  }
@SuppressLint("CommitPrefEdits") @Test public void shouldApplySetOperationByDefault() { BooleanPreference booleanPreference = BooleanPreference.newInstance(mockSharedPreferences, "key", true); booleanPreference.set(false); verify(mockEditor).putBoolean("key", false); verify(mockEditor).apply(); }
@SuppressLint("CommitPrefEdits") @Test public void shouldCommitSetOperation() { BooleanPreference booleanPreference = BooleanPreference.newInstance(mockSharedPreferences, "key", false, true); booleanPreference.set(true); verify(mockEditor).putBoolean("key", true); verify(mockEditor).commit(); }
@SuppressLint("CommitPrefEdits") @Test public void shouldApplySetOperation() { BooleanPreference booleanPreference = BooleanPreference.newInstance(mockSharedPreferences, "key", false, false); booleanPreference.set(true); verify(mockEditor).putBoolean("key", true); verify(mockEditor).apply(); }