### Question:
AuthStateManager { public synchronized void save(final OIDCCredentials authState) { if (authState == null) { clear(); } else { SharedPreferences.Editor e = prefs.edit().putString(KEY_STATE, authState.serialize()); if (!e.commit()) { throw new IllegalStateException("Failed to update state from shared preferences"); } } } private  AuthStateManager(final Context context); OIDCCredentials load(); synchronized void save(final OIDCCredentials authState); synchronized void clear(); static AuthStateManager getInstance();  }### Answer:
@Test public void testSaveNull() { when(mockSharedPreferencesEditor.remove(anyString())) .thenReturn(mockSharedPreferencesEditor); when(mockSharedPreferencesEditor.commit()).thenReturn(true); authStateManager.save(null); verify(mockSharedPreferencesEditor, times(1)).remove(anyString()); }
@Test public void testSaveWithState() { when(mockOIDCCredentials.serialize()).thenReturn("TEST"); when(mockSharedPreferencesEditor.putString(anyString(), anyString())) .thenReturn(mockSharedPreferencesEditor); when(mockSharedPreferencesEditor.commit()).thenReturn(true); authStateManager.save(mockOIDCCredentials); verify(mockSharedPreferencesEditor, times(1)).putString(anyString(), eq("TEST")); }