PagerHelper { public void delete(long pagerId) { PreferenceManager.getDefaultSharedPreferences(mContext) .edit() .remove(getPagerPreferenceKey(pagerId)) .apply(); } PagerHelper(@NonNull final Context context); @NonNull Pager load(long pagerId); void save(@NonNull final Pager pager); void delete(long pagerId);  }
@SuppressLint("CommitPrefEdits") @Test public void testDelete() throws Exception { @SuppressWarnings("StringBufferReplaceableByString") final String jsonString = new StringBuilder().append('{') .append("\"id\":") .append(1234L) .append(",\"size\":") .append(5) .append(",\"position\":") .append(3) .append(",\"history\":[1,4,3,2]") .append('}') .toString(); PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application) .edit() .putString(pagerHelper.getPagerPreferenceKey(1234L), jsonString) .commit(); pagerHelper.delete(1234L); final Pager pagerLoader = pagerHelper.load(1234L); assertEquals(0, pagerLoader.getSize()); assertEquals(0, pagerLoader.getPosition()); assertTrue(pagerLoader.getHistory() .isEmpty()); assertNull(PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application) .getString(pagerHelper.getPagerPreferenceKey(1234L), null)); }