CachedCurrentUserController implements ParseCurrentUserController { @Override public Task<Void> setAsync(final ParseUser user) { return taskQueue.enqueue(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> toAwait) { return toAwait.continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { ParseUser oldCurrentUser; synchronized (mutex) { oldCurrentUser = currentUser; } if (oldCurrentUser != null && oldCurrentUser != user) { return oldCurrentUser.logOutAsync(false).continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { return null; } }); } return task; } }).onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { user.setIsCurrentUser(true); return user.synchronizeAllAuthDataAsync(); } }).onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return store.setAsync(user).continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { synchronized (mutex) { currentUserMatchesDisk = !task.isFaulted(); currentUser = user; } return null; } }); } }); } }); } 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 testSetAsyncWithNoInMemoryCurrentUser() throws Exception { ParseUser.State state = new ParseUser.State.Builder() .put("key", "value") .build(); ParseUser currentUser = ParseObject.from(state); ParseObjectStore<ParseUser> store = (ParseObjectStore<ParseUser>) mock(ParseObjectStore.class); when(store.setAsync(currentUser)).thenReturn(Task.<Void>forResult(null)); CachedCurrentUserController controller = new CachedCurrentUserController(store); ParseTaskUtils.wait(controller.setAsync(currentUser)); verify(store, times(1)).setAsync(currentUser); assertTrue(currentUser.isCurrentUser()); assertSame(currentUser, controller.currentUser); assertTrue(controller.currentUserMatchesDisk); }