@Override public void clearFromDisk() { synchronized (mutex) { currentUser = null; currentUserMatchesDisk = false; } try { ParseTaskUtils.wait(store.deleteAsync()); } catch (ParseException e) { // ignored } }
@Override public void clearFromDisk() { synchronized (mutex) { currentInstallation = null; } try { installationId.clear(); ParseTaskUtils.wait(store.deleteAsync()); } catch (ParseException e) { // ignored } }
@Override public Task<Void> deleteAsync() { final Task<Void> ldsTask = ParseObject.unpinAllInBackground(pinName); return Task.whenAll(Arrays.asList( legacy.deleteAsync(), ldsTask )).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { // We only really care about the result of unpinning. return ldsTask; } }); } }
@Override public Task<T> then(Task<T> task) { final T object = task.getResult(); if (object == null) { return task; } return Task.whenAll(Arrays.asList( from.deleteAsync(), to.setAsync(object) )).continueWith(new Continuation<Void, T>() { @Override public T then(Task<Void> task) { return object; } }); } });
@Test public void testDeleteAsync() throws Exception { OfflineStore lds = mock(OfflineStore.class); when(lds.unpinAllObjectsAsync(anyString())).thenReturn(Task.<Void>forResult(null)); Parse.setLocalDatastore(lds); @SuppressWarnings("unchecked") ParseObjectStore<ParseUser> legacy = mock(ParseObjectStore.class); when(legacy.deleteAsync()).thenReturn(Task.<Void>forResult(null)); OfflineObjectStore<ParseUser> store = new OfflineObjectStore<>(ParseUser.class, PIN_NAME, legacy); ParseTaskUtils.wait(store.deleteAsync()); verify(legacy, times(1)).deleteAsync(); verify(lds, times(1)).unpinAllObjectsAsync(PIN_NAME); }
@Test public void testClearFromDisk() { // Mock installationId InstallationId installationId = mock(InstallationId.class); //noinspection unchecked ParseObjectStore<ParseInstallation> store = mock(ParseObjectStore.class); when(store.deleteAsync()).thenReturn(Task.<Void>forResult(null)); CachedCurrentInstallationController controller = new CachedCurrentInstallationController(store, installationId); controller.currentInstallation = mock(ParseInstallation.class); controller.clearFromDisk(); assertNull(controller.currentInstallation); // Make sure the in LDS currentInstallation is cleared verify(store, times(1)).deleteAsync(); // Make sure installationId is cleared verify(installationId, times(1)).clear(); }
@Test public void testClearFromDisk() { ParseObjectStore<ParseUser> store = (ParseObjectStore<ParseUser>) mock(ParseObjectStore.class); when(store.deleteAsync()).thenReturn(Task.<Void>forResult(null)); CachedCurrentUserController controller = new CachedCurrentUserController(store); controller.currentUser = new ParseUser(); controller.clearFromDisk(); assertNull(controller.currentUser); assertFalse(controller.currentUserMatchesDisk); verify(store, times(1)).deleteAsync(); }
@Test public void testDeleteAsyncFailure() throws Exception { OfflineStore lds = mock(OfflineStore.class); when(lds.unpinAllObjectsAsync(anyString())) .thenReturn(Task.<Void>forError(new RuntimeException("failure"))); Parse.setLocalDatastore(lds); @SuppressWarnings("unchecked") ParseObjectStore<ParseUser> legacy = mock(ParseObjectStore.class); when(legacy.deleteAsync()).thenReturn(Task.<Void>forResult(null)); OfflineObjectStore<ParseUser> store = new OfflineObjectStore<>(ParseUser.class, PIN_NAME, legacy); thrown.expect(RuntimeException.class); ParseTaskUtils.wait(store.deleteAsync()); verify(legacy, times(1)).deleteAsync(); }
@Test public void testLogOutAsyncWithDeleteInDiskCurrentUserSuccess() throws Exception { ParseObjectStore<ParseUser> store = (ParseObjectStore<ParseUser>) mock(ParseObjectStore.class); when(store.deleteAsync()).thenReturn(Task.<Void>forResult(null)); CachedCurrentUserController controller = new CachedCurrentUserController(store); // We set the currentUser to make sure getAsync() return a mock user ParseUser currentUser = mock(ParseUser.class); when(currentUser.logOutAsync()).thenReturn(Task.<Void>forResult(null)); controller.currentUser = currentUser; ParseTaskUtils.wait(controller.logOutAsync()); // Make sure currentUser.logout() is called verify(currentUser, times(1)).logOutAsync(); // Make sure in disk currentUser is deleted verify(store, times(1)).deleteAsync(); // Make sure controller state is correct assertNull(controller.currentUser); assertTrue(controller.currentUserMatchesDisk); }
@Test public void testLogOutAsyncWithDeleteInDiskCurrentUserFailure() throws Exception { ParseObjectStore<ParseUser> store = (ParseObjectStore<ParseUser>) mock(ParseObjectStore.class); when(store.getAsync()).thenReturn(Task.<ParseUser>forResult(null)); when(store.deleteAsync()).thenReturn(Task.<Void>forError(new RuntimeException("failure"))); CachedCurrentUserController controller = new CachedCurrentUserController(store); ParseTaskUtils.wait(controller.logOutAsync()); // Make sure controller state is correct assertNull(controller.currentUser); assertFalse(controller.currentUserMatchesDisk); }
ParseObjectStore<ParseUser> legacy = mock(ParseObjectStore.class); when(legacy.getAsync()).thenReturn(Task.forResult(user)); when(legacy.deleteAsync()).thenReturn(Task.<Void>forResult(null)); .findAsync(any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)); verify(legacy, times(1)).getAsync(); verify(legacy, times(1)).deleteAsync(); verify(lds, times(1)).unpinAllObjectsAsync(PIN_NAME); verify(user, times(1)).pinInBackground(PIN_NAME, false);