CachedCurrentUserController implements ParseCurrentUserController { @Override public Task<Void> logOutAsync() { return taskQueue.enqueue(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> toAwait) { final Task<ParseUser> userTask = getAsync(false); return Task.whenAll(Arrays.asList(userTask, toAwait)).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { Task<Void> logOutTask = userTask.onSuccessTask(new Continuation<ParseUser, Task<Void>>() { @Override public Task<Void> then(Task<ParseUser> task) { ParseUser user = task.getResult(); if (user == null) { return task.cast(); } return user.logOutAsync(); } }); Task<Void> diskTask = store.deleteAsync().continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { boolean deleted = !task.isFaulted(); synchronized (mutex) { currentUserMatchesDisk = deleted; currentUser = null; } return null; } }); return Task.whenAll(Arrays.asList(logOutTask, diskTask)); } }); } }); } CachedCurrentUserController(ParseObjectStore<ParseUser> store); @Override Task<Void> setAsync(final ParseUser user); @Override Task<Void> setIfNeededAsync(ParseUser user); @Override Task<ParseUser> getAsync(); @Override Task<Boolean> existsAsync(); @Override boolean isCurrent(ParseUser user); @Override void clearFromMemory(); @Override void clearFromDisk(); @Override Task<String> getCurrentSessionTokenAsync(); @Override Task<Void> logOutAsync(); @Override Task<ParseUser> getAsync(final boolean shouldAutoCreateUser);  }
@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); ParseUser currentUser = mock(ParseUser.class); when(currentUser.logOutAsync()).thenReturn(Task.<Void>forResult(null)); controller.currentUser = currentUser; ParseTaskUtils.wait(controller.logOutAsync()); verify(currentUser, times(1)).logOutAsync(); verify(store, times(1)).deleteAsync(); assertNull(controller.currentUser); assertTrue(controller.currentUserMatchesDisk); }