PreferencesUtils { public void touchLastSurveyed(boolean responseSent, Integer resurvey_days) { final SharedPreferences prefs = prefs(); if(prefs == null) return; SharedPreferences.Editor editor = prefs.edit(); if(editor == null) return; editor.putLong(KEY_LAST_SURVEYED, new Date().getTime()); if (responseSent) { editor.putString(KEY_TYPE, "response"); } else { editor.putString(KEY_TYPE, "decline"); } editor.putInt(KEY_RESURVEY_DAYS, resurvey_days); editor.apply(); } PreferencesUtils(WeakReference<Context> weakContext); void touchLastSurveyed(boolean responseSent, Integer resurvey_days); boolean wasRecentlySurveyed(); void touchLastSeen(); long getLastSeen(); boolean isLastSeenSet(); void putResponse(String response); String getResponse(); void putDecline(String decline); String getDecline();  }
@Test public void touchLastSurveyed_whenResponse() throws Exception { SharedPreferences.Editor mockedEditor = Mockito.mock(SharedPreferences.Editor.class); Mockito.when(prefs.edit()).thenReturn(mockedEditor); preferencesUtils.touchLastSurveyed(true, 90); Mockito.verify(mockedEditor).apply(); }