@Test public void readString_exception() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); sharedPreferences.edit().putInt("test_key", 123).apply(); String defValue = "def_value"; String result = iabSharedPreference.readString(sharedPreferences, "test_key", defValue); assertNotNull(result); assertEquals(defValue, result); }
@Nullable @VisibleForTesting String readString(@NonNull SharedPreferences sharedPreferences, @NonNull String key, @Nullable String defValue) { try { String result = sharedPreferences.getString(key, defValue); return result != null ? result : defValue; } catch (Exception e) { return defValue; } }
IABSharedPreference { @Nullable @VisibleForTesting String readString(@NonNull SharedPreferences sharedPreferences, @NonNull String key, @Nullable String defValue) { try { String result = sharedPreferences.getString(key, defValue); return result != null ? result : defValue; } catch (Exception e) { return defValue; } } }
IABSharedPreference { @Nullable @VisibleForTesting String readString(@NonNull SharedPreferences sharedPreferences, @NonNull String key, @Nullable String defValue) { try { String result = sharedPreferences.getString(key, defValue); return result != null ? result : defValue; } catch (Exception e) { return defValue; } } IABSharedPreference(); }
IABSharedPreference { @Nullable @VisibleForTesting String readString(@NonNull SharedPreferences sharedPreferences, @NonNull String key, @Nullable String defValue) { try { String result = sharedPreferences.getString(key, defValue); return result != null ? result : defValue; } catch (Exception e) { return defValue; } } IABSharedPreference();  }
IABSharedPreference { @Nullable @VisibleForTesting String readString(@NonNull SharedPreferences sharedPreferences, @NonNull String key, @Nullable String defValue) { try { String result = sharedPreferences.getString(key, defValue); return result != null ? result : defValue; } catch (Exception e) { return defValue; } } IABSharedPreference();   }